client.cpp 455 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "../common/debug.h"
  17. #include "../common/Log.h"
  18. #include <iostream>
  19. #include <iomanip>
  20. #include <string.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <math.h>
  24. #include <zlib.h>
  25. #include <assert.h>
  26. #include <algorithm>
  27. #include "Player.h"
  28. #include "Commands/Commands.h"
  29. #include "ClientPacketFunctions.h"
  30. #include "../common/ConfigReader.h"
  31. #include "Guilds/Guild.h"
  32. #include "Variables.h"
  33. #include "Rules/Rules.h"
  34. #include "Titles.h"
  35. #include "Chat/Chat.h"
  36. #include "SpellProcess.h"
  37. #include "Zone/ChestTrap.h"
  38. #include "../../common/GlobalHeaders.h"
  39. //#include "Quests.h"
  40. #ifdef WIN32
  41. #include <WinSock2.h>
  42. #include <windows.h>
  43. #define snprintf _snprintf
  44. #define vsnprintf _vsnprintf
  45. #define strncasecmp _strnicmp
  46. #define strcasecmp _stricmp
  47. #else
  48. #include <sys/socket.h>
  49. #ifdef FREEBSD
  50. #include <sys/types.h>
  51. #endif
  52. #include <netinet/in.h>
  53. #include <arpa/inet.h>
  54. #include <unistd.h>
  55. #endif
  56. #if defined(__GNUC__)
  57. #define _snprintf snprintf
  58. #endif
  59. #include "client.h"
  60. #include "../common/emu_opcodes.h"
  61. #include "../common/packet_dump.h"
  62. #include "WorldDatabase.h"
  63. #include "races.h"
  64. #include "classes.h"
  65. #include "LoginServer.h"
  66. #include "World.h"
  67. #include "../common/EQ2_Common_Structs.h"
  68. #include "net.h"
  69. #include "../common/MiscFunctions.h"
  70. #include "Skills.h"
  71. #include "LuaInterface.h"
  72. #include "Quests.h"
  73. #include "Collections/Collections.h"
  74. #include "Achievements/Achievements.h"
  75. #include "Traits/Traits.h"
  76. #include "Recipes/Recipe.h"
  77. #include "Tradeskills/Tradeskills.h"
  78. #include "AltAdvancement/AltAdvancement.h"
  79. #include "Bots/Bot.h"
  80. #include "VisualStates.h"
  81. extern WorldDatabase database;
  82. extern const char* ZONE_NAME;
  83. extern LoginServer loginserver;
  84. extern sint32 numclients;
  85. extern NetConnection net;
  86. extern Commands commands;
  87. extern ClientList client_list;
  88. extern ZoneList zone_list;
  89. extern ZoneAuth zone_auth;
  90. extern MasterItemList master_item_list;
  91. extern MasterSkillList master_skill_list;
  92. extern MasterSpellList master_spell_list;
  93. extern MasterTraitList master_trait_list;
  94. extern MasterQuestList master_quest_list;
  95. extern MasterFactionList master_faction_list;
  96. extern MasterRecipeList master_recipe_list;
  97. extern volatile bool RunLoops;
  98. extern ConfigReader configReader;
  99. extern LuaInterface* lua_interface;
  100. extern World world;
  101. extern Variables variables;
  102. extern Classes classes;
  103. extern Races races;
  104. extern GuildList guild_list;
  105. extern MasterCollectionList master_collection_list;
  106. extern MasterAchievementList master_achievement_list;
  107. extern RuleManager rule_manager;
  108. extern Chat chat;
  109. extern MasterAAList master_aa_list;
  110. extern MasterAAList master_tree_nodes;
  111. extern ChestTrapList chest_trap_list;
  112. extern MasterRecipeBookList master_recipebook_list;
  113. extern VisualStates visual_states;
  114. using namespace std;
  115. 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) {
  116. eqs = ieqs;
  117. ip = eqs->GetrIP();
  118. port = ntohs(eqs->GetrPort());
  119. merchant_transaction = nullptr;
  120. mail_window.item = nullptr; // don't want this to be set(loose ptr) when using ResetSendMail to provide rest of the defaults
  121. ResetSendMail(false);
  122. timestamp_flag = 0;
  123. current_quest_id = 0;
  124. last_update_time = 0;
  125. quest_updates = false;
  126. //autobootup_timeout = new Timer(10000);
  127. //autobootup_timeout->Disable();
  128. CLE_keepalive_timer = new Timer(15000);
  129. connect = new Timer(1000);
  130. connect->Disable();
  131. zoneID = 0;
  132. account_name[0] = 0;
  133. character_id = 0;
  134. account_id = 0;
  135. pwaitingforbootup = 0;
  136. current_zone = 0;
  137. connected_to_zone = false;
  138. connected = false;
  139. camp_timer = 0;
  140. linkdead_timer = 0;
  141. client_zoning = false;
  142. zoning_id = 0;
  143. zoning_x = 0;
  144. zoning_y = 0;
  145. zoning_z = 0;
  146. zoning_instance_id = 0;
  147. player_pos_changed = false;
  148. player_pos_timer = Timer::GetCurrentTime2()+1000;
  149. enabled_player_pos_timer = true;
  150. ++numclients;
  151. if (world.GetServerStatisticValue(STAT_SERVER_MOST_CONNECTIONS) < numclients)
  152. world.UpdateServerStatistic(STAT_SERVER_MOST_CONNECTIONS, numclients, true);
  153. remove_from_list = false;
  154. new_client_login = NewLoginState::LOGIN_NONE;
  155. UpdateWindowTitle(0);
  156. num_active_failures = 0;
  157. player = new Player();
  158. player->SetClient(this);
  159. combine_spawn = 0;
  160. lua_debug = false;
  161. ready_for_spawns = false;
  162. ready_for_updates = false;
  163. lua_debug_timer.Disable();
  164. transport_spawn = 0;
  165. MBuyBack.SetName("Client::MBuyBack");
  166. MDeletePlayer.SetName("Client::MDeletePlayer");
  167. MQuestPendingUpdates.SetName("Client::MQuestPendingUpdates");
  168. search_items = 0;
  169. version = 0;
  170. next_conversation_id = 0;
  171. pending_guild_invite.guild = 0;
  172. pending_guild_invite.invited_by = 0;
  173. m_recipeListSent = false;
  174. m_resurrect.SetName("Client::m_resurrect");
  175. current_rez.expire_timer = 0;
  176. current_rez.should_delete = true;
  177. pending_last_name = 0;
  178. should_target = false;
  179. initial_spawns_sent = false;
  180. MQuestTimers.SetName("Client::quest_timers");
  181. memset(&incoming_paperdoll, 0, sizeof(incoming_paperdoll));
  182. on_auto_mount = false;
  183. should_load_spells = true;
  184. spawnPlacementMode = ServerSpawnPlacementMode::DEFAULT;
  185. delayedLogin = false;
  186. delayedAccountID = 0;
  187. delayedAccessKey = 0;
  188. delayTimer.Disable();
  189. tempPlacementSpawn = nullptr;
  190. placement_unique_item_id = 0;
  191. SetHasOwnerOrEditAccess(false);
  192. temporary_transport_id = 0;
  193. rejoin_group_id = 0;
  194. lastRegionRemapTime = 0;
  195. regionDebugMessaging = false;
  196. client_reloading_zone = false;
  197. last_saved_timestamp = 0;
  198. MQueueStateCmds.SetName("Client::MQueueStateCmds");
  199. save_spell_state_timer.Disable();
  200. save_spell_state_time_bucket = 0;
  201. player_loading_complete = false;
  202. MItemDetails.SetName("Client::MItemDetails");
  203. MSpellDetails.SetName("Client::MSpellDetails");
  204. hasSentTempPlacementSpawn = false;
  205. spawn_removal_timer.Start();
  206. disable_save = false;
  207. SetZoningDestination(nullptr);
  208. underworld_cooldown_timer.Disable();
  209. player_pos_change_count = 0;
  210. pov_ghost_spawn_id = 0;
  211. recipe_orig_packet = nullptr;
  212. recipe_xor_packet = nullptr;
  213. recipe_packet_count = 0;
  214. recipe_orig_packet_size = 0;
  215. }
  216. Client::~Client() {
  217. RemoveClientFromZone();
  218. //let the stream factory know were done with this stream
  219. if (eqs) {
  220. eqs->Close();
  221. try {
  222. eqs->ReleaseFromUse();
  223. }
  224. catch (...) {}
  225. }
  226. eqs = NULL;
  227. //safe_delete(autobootup_timeout);
  228. safe_delete(linkdead_timer);
  229. vector<QueuedQuest*>::iterator itr;
  230. QueuedQuest* queued_quest = 0;
  231. for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
  232. queued_quest = *itr;
  233. safe_delete(queued_quest);
  234. }
  235. quest_queue.clear();
  236. vector<QuestRewardData*>::iterator rwd_itr;
  237. QuestRewardData* quest_rwd_data = 0;
  238. for (rwd_itr = quest_pending_reward.begin(); rwd_itr != quest_pending_reward.end(); rwd_itr++) {
  239. quest_rwd_data = *rwd_itr;
  240. safe_delete(quest_rwd_data);
  241. }
  242. quest_pending_reward.clear();
  243. safe_delete(CLE_keepalive_timer);
  244. safe_delete(connect);
  245. --numclients;
  246. UpdateWindowTitle(0);
  247. }
  248. void Client::RemoveClientFromZone() {
  249. if(player && player->GetZone())
  250. player->GetZone()->GetSpellProcess()->RemoveSpellTimersFromSpawn(player, true, false, true, true);
  251. if (GetTempPlacementSpawn() && GetCurrentZone()) {
  252. Spawn* tmp = GetTempPlacementSpawn();
  253. SetTempPlacementSpawn(nullptr);
  254. GetCurrentZone()->RemoveSpawn(tmp, true, false, true, true, true);
  255. }
  256. if (current_zone && player) {
  257. if (player->GetGroupMemberInfo()) {
  258. TempRemoveGroup();
  259. }
  260. world.GetGroupManager()->ClearPendingInvite(player);
  261. }
  262. if (lua_interface)
  263. lua_interface->RemoveDebugClients(this);
  264. if (player)
  265. zone_list.RemoveClientFromMap(player->GetName(), this);
  266. safe_delete(camp_timer);
  267. safe_delete(search_items);
  268. safe_delete(current_rez.expire_timer);
  269. safe_delete(pending_last_name);
  270. safe_delete_array(incoming_paperdoll.image_bytes);
  271. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  272. player = nullptr;
  273. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  274. deque<BuyBackItem*>::iterator itr;
  275. MBuyBack.writelock(__FUNCTION__, __LINE__);
  276. for (itr = buy_back_items.begin(); itr != buy_back_items.end();) {
  277. safe_delete(*itr);
  278. itr = buy_back_items.erase(itr);
  279. }
  280. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  281. }
  282. void Client::QueuePacket(EQ2Packet* app, bool attemptedCombine) {
  283. if (eqs) {
  284. if (!eqs->CheckActive()) {
  285. client_list.Remove(this);
  286. eqs = 0;
  287. }
  288. }
  289. if (app && eqs && version > 0)
  290. eqs->EQ2QueuePacket(app, attemptedCombine);
  291. else {
  292. safe_delete(app);
  293. }
  294. }
  295. void Client::PopulateSkillMap() {
  296. EQ2Packet* app = master_skill_list.GetPopulateSkillsPacket(GetVersion());
  297. if (app)
  298. QueuePacket(app);
  299. else {
  300. LogWrite(WORLD__ERROR, 0, "World", "Unable to send populate skills packet for version: %i!", GetVersion());
  301. Disconnect(); //the client cant proceed without the skill packet, might as well kick it now
  302. }
  303. }
  304. void Client::SendLoginInfo() {
  305. if(GetPlayer()->IsReturningFromLD())
  306. firstlogin = true;
  307. if (firstlogin) {
  308. LogWrite(WORLD__DEBUG, 0, "World", "Increment Server_Accepted_Connection + 1");
  309. world.UpdateServerStatistic(STAT_SERVER_ACCEPTED_CONNECTION, 1);
  310. LogWrite(CCLIENT__DEBUG, 0, "Client", "Populate Skill Map...");
  311. PopulateSkillMap();
  312. // 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!
  313. LogWrite(MISC__TODO, 1, "TODO", "Check client version at login, move char if invalid zone file");
  314. }
  315. LogWrite(CCLIENT__DEBUG, 0, "Client", "Toggle Character Online...");
  316. database.ToggleCharacterOnline(this, 1);
  317. int32 count = 0;
  318. if(!GetPlayer()->IsReturningFromLD())
  319. {
  320. count = database.LoadCharacterTitles(GetCharacterID(), player);
  321. if (count == 0) {
  322. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character titles found!");
  323. LogWrite(CCLIENT__DEBUG, 0, "Client", "Initializing starting values - Titles");
  324. database.UpdateStartingTitles(GetCharacterID(), player->GetAdventureClass(), player->GetRace(), player->GetGender());
  325. }
  326. }
  327. if(!GetPlayer()->IsReturningFromLD())
  328. {
  329. count = database.LoadCharacterLanguages(GetCharacterID(), player);
  330. if (count == 0)
  331. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character languages loaded!");
  332. count = database.LoadPlayerRecipeBooks(GetCharacterID(), player);
  333. if (count == 0)
  334. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character recipe books found!");
  335. }
  336. ClientPacketFunctions::SendLoginAccepted(this);
  337. ClientPacketFunctions::SendAbilities ( this );
  338. ClientPacketFunctions::SendCommandNamePacket(this);
  339. ClientPacketFunctions::SendQuickBarInit(this);
  340. // we only need to send the MOTD if it is the first time the person is logging in.
  341. if (firstlogin) {
  342. ClientPacketFunctions::SendMOTD(this);
  343. ClientPacketFunctions::SendCharacterMacros(this);
  344. zone_list.CheckFriendList(this);
  345. }
  346. if(!GetPlayer()->IsReturningFromLD())
  347. {
  348. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  349. if (firstlogin && player->item_list.GetNumberOfItems() == 0 && player->GetEquipmentList()->GetNumberOfItems() == 0) //re-add starting items if missing
  350. {
  351. LogWrite(CCLIENT__WARNING, 0, "Client", "Player has no items - reloading starting items: '%s' (%u)", player->GetName(), GetCharacterID());
  352. database.UpdateStartingItems(GetCharacterID(), player->GetAdventureClass(), player->GetRace());
  353. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  354. }
  355. GetPlayer()->item_list.SetMaxItemIndex();
  356. database.LoadPlayerFactions(this);
  357. database.LoadCharacterQuests(this);
  358. database.LoadCharacterQuestRewards(this);
  359. database.LoadPlayerMail(this);
  360. }
  361. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  362. SendQuestJournal(true, 0, false);
  363. if (version > 561) // right version? possibly not!
  364. master_aa_list.DisplayAA(this, 0, 3);
  365. if (version > 373)
  366. SendCollectionList();
  367. SendBiography();
  368. map<int32, Quest*>::iterator itr;
  369. Quest* quest = 0;
  370. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  371. for (itr = player->player_quests.begin(); itr != player->player_quests.end(); itr++) {
  372. quest = itr->second;
  373. if (quest->IsTracked()) {
  374. quest->SetTracked(false);
  375. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  376. quest->SetTracked(true);
  377. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  378. }
  379. }
  380. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  381. // SendAchievementsList();
  382. /*Guild* guild = player->GetGuild();
  383. if (guild) {
  384. guild->UpdateGuildMemberInfo(GetPlayer());
  385. if (firstlogin)
  386. guild->SendGuildMOTD(this);
  387. guild->SendGuildUpdate(this);
  388. guild->SendGuildMember(GetPlayer(), firstlogin);
  389. guild->SendGuildEventList(this);
  390. guild->SendGuildBankEventList(this);
  391. guild->SendAllGuildEvents(this);
  392. guild->SendGuildMemberList(this);
  393. }*/
  394. if (version > 373) {
  395. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Faction Updates...");
  396. EQ2Packet* outapp = player->GetFactions()->FactionUpdate(GetVersion());
  397. if (outapp) {
  398. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  399. //DumpPacket(outapp);
  400. QueuePacket(outapp);
  401. }
  402. }
  403. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Command List...");
  404. ClientPacketFunctions::SendCommandList(this);
  405. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Language Updates...");
  406. // kos doesn't like one of these language or instance list
  407. SendLanguagesUpdate(database.GetCharacterCurrentLang(GetCharacterID(), player));
  408. //ClientPacketFunctions::SendInstanceList(this);
  409. SendZoneInfo();
  410. /*Spell* spell = 0;
  411. vector<QuickBarItem*>::iterator itr;
  412. for(itr = player->GetQuickbar()->begin(); itr != player->GetQuickbar()->end(); itr++){
  413. if((*itr)->type == 1){
  414. spell = master_spell_list.GetSpell((*itr)->id);
  415. if(spell)
  416. QueuePacket(spell->serialize(this, false, 0x20));
  417. }
  418. }*/
  419. }
  420. void Client::SendPlayerDeathWindow()
  421. {
  422. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendPlayerDeathWindow");
  423. vector<RevivePoint*>* results = GetCurrentZone()->GetRevivePoints(this);
  424. vector<RevivePoint*>::iterator itr;
  425. if (results && results->size() > 0)
  426. {
  427. PacketStruct* packet = configReader.getStruct("WS_DeathWindow", GetVersion());
  428. if (packet)
  429. {
  430. packet->setArrayLengthByName("location_count", results->size());
  431. RevivePoint* point = 0;
  432. int32 i = 0;
  433. for (itr = results->begin(); itr != results->end(); itr++, i++)
  434. {
  435. point = *itr;
  436. if (point)
  437. {
  438. packet->setArrayDataByName("location_id", point->id, i);
  439. //zone_name = database.GetZoneName(point->zone_id);
  440. string zone_name = database.GetZoneDescription(point->zone_id);
  441. if (zone_name.length() > 0)
  442. packet->setArrayDataByName("zone_name", zone_name.c_str(), i);
  443. packet->setArrayDataByName("location_name", point->location_name.c_str(), i);
  444. packet->setArrayDataByName("distance", GetPlayer()->GetDistance(point->x, point->y, point->z), i);
  445. }
  446. if (point->id == 0xFFFFFFFF)//tmp location
  447. safe_delete(point);
  448. }
  449. #if EQDEBUG >= 3
  450. LogWrite(CCLIENT__DEBUG, 0, "Client", "WS_DeathWindow Packet:");
  451. packet->PrintPacket();
  452. #endif
  453. EQ2Packet* outapp = packet->serialize();
  454. QueuePacket(outapp);
  455. safe_delete(packet);
  456. }
  457. // done with the revive points so lets free up the pointer
  458. safe_delete(results);
  459. }
  460. }
  461. void Client::DisplayDeadWindow()
  462. {
  463. LogWrite(ZONE__DEBUG, 0, "Zone", "DisplayDeadWindow()");
  464. player->SetHP(0);
  465. player->SetPower(0);
  466. GetCurrentZone()->TriggerCharSheetTimer();
  467. if(GetVersion() <= 561) {
  468. ClientPacketFunctions::SendServerControlFlagsClassic(this, 8, 1);
  469. ClientPacketFunctions::SendServerControlFlagsClassic(this, 16, 1);
  470. }
  471. else {
  472. ClientPacketFunctions::SendServerControlFlags(this, 1, 8, 1);
  473. ClientPacketFunctions::SendServerControlFlags(this, 1, 16, 1);
  474. }
  475. PacketStruct* packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  476. if (packet)
  477. {
  478. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  479. QueuePacket(packet->serialize());
  480. safe_delete(packet);
  481. }
  482. SendPlayerDeathWindow();
  483. }
  484. void Client::HandlePlayerRevive(int32 point_id)
  485. {
  486. if(GetVersion() <= 561) {
  487. ClientPacketFunctions::SendServerControlFlagsClassic(this, 8, 0);
  488. ClientPacketFunctions::SendServerControlFlagsClassic(this, 16, 0);
  489. }
  490. else {
  491. ClientPacketFunctions::SendServerControlFlags(this, 1, 8, 0);
  492. ClientPacketFunctions::SendServerControlFlags(this, 1, 16, 0);
  493. }
  494. SimpleMessage(CHANNEL_NARRATIVE, "You regain consciousness!");
  495. PacketStruct* packet = configReader.getStruct("WS_Resurrected", GetVersion());
  496. if (packet)
  497. {
  498. QueuePacket(packet->serialize());
  499. safe_delete(packet);
  500. }
  501. float origX, origY, origZ, origHeading = 0.0f;
  502. origX = player->GetX();
  503. origY = player->GetY();
  504. origZ = player->GetZ();
  505. origHeading = player->GetHeading();
  506. ZoneServer* originalZone = GetCurrentZone();
  507. int32 origGridID = GetPlayer()->GetLocation();
  508. float x, y, z, heading;
  509. RevivePoint* revive_point = 0;
  510. if (point_id != 0xFFFFFFFF)
  511. revive_point = GetCurrentZone()->GetRevivePoint(point_id);
  512. string zone_desc;
  513. const char* location_name = "Unknown";
  514. player->SetAlive(true);
  515. player->SetResurrecting(true);
  516. player->SetHP(player->GetTotalHP());
  517. player->SetPower(player->GetTotalPower());
  518. //revive at zone safe coords
  519. if (!revive_point)
  520. {
  521. LogWrite(CCLIENT__WARNING, 0, "Client", "No Revive Point! Spawning player at safe coordinates!");
  522. x = GetCurrentZone()->GetSafeX();
  523. y = GetCurrentZone()->GetSafeY();
  524. z = GetCurrentZone()->GetSafeZ();
  525. heading = GetCurrentZone()->GetSafeHeading();
  526. zone_desc = GetCurrentZone()->GetZoneDescription();
  527. location_name = "Zone Safe Point";
  528. Zone(GetCurrentZone()->GetZoneName(), false);
  529. }
  530. else
  531. {
  532. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to chosen Revive Point.");
  533. x = revive_point->x;
  534. y = revive_point->y;
  535. z = revive_point->z;
  536. heading = revive_point->heading;
  537. zone_desc = database.GetZoneDescription(revive_point->zone_id);
  538. location_name = revive_point->location_name.c_str();
  539. Zone(GetCurrentZone()->GetZoneName(), false);
  540. }
  541. player->SetX(x);
  542. player->SetY(y);
  543. player->SetZ(z);
  544. player->SetHeading(heading);
  545. LogWrite(CCLIENT__DEBUG, 0, "Client", "Attempt Revive @ %s, %.2f, %.2f, %.2f, %.2f, HP: %i, Pow: %i, %s",
  546. zone_desc.c_str(),
  547. player->GetX(),
  548. player->GetY(),
  549. player->GetZ(),
  550. player->GetHeading(),
  551. player->GetHP(),
  552. player->GetPower(),
  553. location_name);
  554. //player->ClearEverything();
  555. Save();
  556. if (revive_point && revive_point->zone_id != GetCurrentZone()->GetZoneID() && revive_point->zone_id != 0)
  557. {
  558. string zone_name = database.GetZoneName(revive_point->zone_id);
  559. if (zone_name.length() == 0)
  560. {
  561. LogWrite(CCLIENT__WARNING, 0, "Client", "Unable to zone player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  562. x = GetCurrentZone()->GetSafeX();
  563. y = GetCurrentZone()->GetSafeY();
  564. z = GetCurrentZone()->GetSafeZ();
  565. heading = GetCurrentZone()->GetSafeHeading();
  566. location_name = "Zone Safe Point";
  567. }
  568. else
  569. {
  570. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  571. location_name = revive_point->location_name.c_str();
  572. //player->ClearEverything();
  573. Save();
  574. Zone(zone_name.c_str(), false);
  575. }
  576. }
  577. zone_desc = GetCurrentZone()->GetZoneDescription();
  578. Message(CHANNEL_NARRATIVE, "Reviving in %s at %s.", zone_desc.c_str(), location_name);
  579. player->SetSpawnType(4);
  580. if (version > 373) {
  581. packet = configReader.getStruct("WS_CancelMoveObjectMode", GetVersion());
  582. if (packet)
  583. {
  584. QueuePacket(packet->serialize());
  585. safe_delete(packet);
  586. }
  587. }
  588. packet = configReader.getStruct("WS_TeleportWithinZone", GetVersion());
  589. if (packet)
  590. {
  591. packet->setDataByName("x", x);
  592. packet->setDataByName("y", y);
  593. packet->setDataByName("z", z);
  594. QueuePacket(packet->serialize());
  595. safe_delete(packet);
  596. }
  597. SendControlGhost();
  598. packet = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  599. if (packet)
  600. {
  601. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  602. QueuePacket(packet->serialize());
  603. safe_delete(packet);
  604. }
  605. if(rule_manager.GetGlobalRule(R_Combat, EnableSpiritShards)->GetBool())
  606. {
  607. NPC* shard = player->InstantiateSpiritShard(origX, origY, origZ, origHeading, origGridID, originalZone);
  608. if(shard->GetSpawnScript() && strlen(shard->GetSpawnScript()) > 0)
  609. originalZone->CallSpawnScript(shard, SPAWN_SCRIPT_PRESPAWN);
  610. originalZone->RemoveSpawn(player, false, true, true, true, true);
  611. originalZone->AddSpawn(shard);
  612. if(shard->GetSpawnScript() && strlen(shard->GetSpawnScript()) > 0)
  613. originalZone->CallSpawnScript(shard, SPAWN_SCRIPT_SPAWN);
  614. }
  615. m_resurrect.writelock(__FUNCTION__, __LINE__);
  616. if (current_rez.active)
  617. current_rez.should_delete = true;
  618. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  619. }
  620. void Client::SendControlGhost(int32 send_id, int8 unknown2) {
  621. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", GetVersion());
  622. if (packet) {
  623. packet->setDataByName("spawn_id", send_id);
  624. packet->setDataByName("speed", GetPlayer()->GetSpeed());
  625. packet->setDataByName("size", 0.51);
  626. packet->setDataByName("unknown2", unknown2);
  627. packet->setDataByName("air_speed", player->GetAirSpeed());
  628. EQ2Packet* app = packet->serialize();
  629. QueuePacket(app);
  630. safe_delete(packet);
  631. }
  632. }
  633. void Client::SendCharInfo() {
  634. EQ2Packet* app;
  635. player->SetEquippedItemAppearances();
  636. ClientPacketFunctions::SendCharacterData(this);
  637. SendCharPOVGhost();
  638. SendControlGhost(player->GetIDWithPlayerSpawn(player), 255);
  639. //sending bad spawn packet?
  640. //SendAchievementsList();
  641. //if (version > 561)
  642. //ClientPacketFunctions::SendHousingList(this);
  643. ClientPacketFunctions::SendCharacterSheet(this);
  644. ClientPacketFunctions::SendTraitList(this);// moved from below
  645. ClientPacketFunctions::SendAbilities(this);
  646. ClientPacketFunctions::SendSkillBook(this);
  647. if (!IsReloadingZone() && !player->IsResurrecting() && GetVersion() >= 546) {
  648. ClientPacketFunctions::SendUpdateSpellBook(this);
  649. }
  650. else {
  651. player->SetResurrecting(false);
  652. }
  653. GetCurrentZone()->AddSpawn(player);
  654. if(IsReloadingZone() && (zoning_x || zoning_y || zoning_z)) {
  655. GetPlayer()->SetX(zoning_x);
  656. GetPlayer()->SetY(zoning_y);
  657. GetPlayer()->SetZ(zoning_z);
  658. GetPlayer()->SetHeading(zoning_h);
  659. EQ2Packet* packet = GetPlayer()->Move(zoning_x, zoning_y, zoning_z, GetVersion(), zoning_h);
  660. QueuePacket(packet);
  661. }
  662. //SendCollectionList();
  663. Guild* guild = player->GetGuild();
  664. if (guild)
  665. guild->GuildMemberLogin(this, firstlogin);
  666. app = player->GetPlayerItemList()->serialize(GetPlayer(), GetVersion());
  667. if (app) {
  668. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  669. //DumpPacket(app);
  670. QueuePacket(app);
  671. }
  672. app = player->GetEquipmentList()->serialize(GetVersion(), player);
  673. if (app) {
  674. QueuePacket(app);
  675. }
  676. app = player->GetAppearanceEquipmentList()->serialize(GetVersion(), player);
  677. if (app) {
  678. QueuePacket(app);
  679. }
  680. vector<Item*>* items = player->GetPlayerItemList()->GetItemsFromBagID(-3); // bank items
  681. if (items && items->size() > 0) {
  682. for (int32 i = 0; i < items->size(); i++) {
  683. EQ2Packet* outapp = items->at(i)->serialize(GetVersion(), false, GetPlayer());
  684. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  685. //DumpPacket(outapp);
  686. QueuePacket(outapp);
  687. }
  688. }
  689. if (firstlogin && (app = chat.GetWorldChannelList(this)) != NULL)
  690. QueuePacket(app);
  691. safe_delete(items);
  692. items = player->GetPlayerItemList()->GetItemsFromBagID(-4); //shared bank items
  693. if (items && items->size() > 0) {
  694. for (int32 i = 0; i < items->size(); i++)
  695. QueuePacket(items->at(i)->serialize(GetVersion(), false, GetPlayer()));
  696. }
  697. safe_delete(items);
  698. if (version >= 373) {
  699. SendTitleUpdate();
  700. }
  701. GetPlayer()->UpdateWeapons();
  702. if(!GetPlayer()->IsReturningFromLD()) {
  703. database.LoadBuyBacks(this);
  704. }
  705. if (version > 561)
  706. master_aa_list.DisplayAA(this, 0, 0);
  707. string zone_motd = GetCurrentZone()->GetZoneMOTD();
  708. if (zone_motd.length() > 0 && zone_motd[0] != ' ') {
  709. string zone_motd_send = "Zone MOTD: " + zone_motd;
  710. SimpleMessage(CHANNEL_NARRATIVE, zone_motd_send.c_str());
  711. }
  712. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  713. if (zone_script && lua_interface)
  714. lua_interface->RunZoneScript(zone_script, "player_entry", GetCurrentZone(), GetPlayer());
  715. this->client_zoning = false;
  716. this->zoning_id = 0;
  717. this->zoning_instance_id = 0;
  718. SetZoningDestination(nullptr);
  719. if (player->GetHP() < player->GetTotalHP() || player->GetPower() < player->GetTotalPower())
  720. GetCurrentZone()->AddDamagedSpawn(player);
  721. if (firstlogin)
  722. firstlogin = false;
  723. player->ClearProcs();
  724. items = player->GetEquippedItemList();
  725. if (items && items->size() > 0) {
  726. for (int32 i = 0; i < items->size(); i++) {
  727. Item* item = items->at(i);
  728. if (item && item->GetItemScript() && lua_interface)
  729. lua_interface->RunItemScript(item->GetItemScript(), "equipped", item, player);
  730. }
  731. }
  732. //Allow this player to change their last name if they meet the level requirement
  733. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && player->GetLevel() >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  734. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  735. safe_delete(items);
  736. if (!player->Alive())
  737. DisplayDeadWindow();
  738. ClientPacketFunctions::SendLocalizedTextMessage(this);
  739. if (GetCurrentZone()->GetInstanceID())
  740. {
  741. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(GetCurrentZone()->GetInstanceID());
  742. if (ph) {
  743. //HouseZone* hz = world.GetHouseZone(ph->house_id);
  744. string name = string(GetPlayer()->GetName());
  745. if (name.compare(ph->player_name) == 0)
  746. SetHasOwnerOrEditAccess(true);
  747. }
  748. }
  749. bool groupMentor = false;
  750. GetPlayer()->group_id = rejoin_group_id;
  751. if(!world.RejoinGroup(this, rejoin_group_id))
  752. GetPlayer()->group_id = 0;
  753. else
  754. {
  755. Entity* ent = world.GetGroupManager()->IsPlayerInGroup(rejoin_group_id, GetPlayer()->GetGroupMemberInfo()->mentor_target_char_id);
  756. if(ent && ent->IsPlayer())
  757. {
  758. GetPlayer()->SetMentorStats(ent->GetLevel(), ent->GetID(), false);
  759. groupMentor = true;
  760. }
  761. }
  762. if(!groupMentor)
  763. GetPlayer()->SetMentorStats(GetPlayer()->GetLevel(), 0, false);
  764. if(!GetPlayer()->IsReturningFromLD()) {
  765. database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_MAINTAINEDEFFECTS);
  766. database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_SPELLEFFECTS);
  767. }
  768. else {
  769. Spawn* pet_spawn = nullptr;
  770. if(GetPlayer()->GetPet())
  771. pet_spawn = GetPlayer()->GetPet();
  772. else if(GetPlayer()->GetCharmedPet())
  773. pet_spawn = GetPlayer()->GetCharmedPet();
  774. else if(GetPlayer()->GetCosmeticPet())
  775. pet_spawn = GetPlayer()->GetCosmeticPet();
  776. else if(GetPlayer()->GetDeityPet())
  777. pet_spawn = GetPlayer()->GetDeityPet();
  778. if(pet_spawn) {
  779. GetPlayer()->GetInfoStruct()->set_pet_id(GetPlayer()->GetIDWithPlayerSpawn(pet_spawn));
  780. }
  781. }
  782. GetPlayer()->SetSaveSpellEffects(false);
  783. GetPlayer()->SetCharSheetChanged(true);
  784. GetPlayer()->SetReturningFromLD(false);
  785. }
  786. void Client::SendZoneSpawns() {
  787. //Allows us to place spawns almost anywhere
  788. if (version > 373) {
  789. uchar blah[] = { 0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46 };
  790. EQ2Packet* app = new EQ2Packet(OP_MoveableObjectPlacementCriteri, blah, sizeof(blah));
  791. QueuePacket(app);
  792. }
  793. ClientPacketFunctions::SendSkillSlotMappings(this);
  794. ClientPacketFunctions::SendGameWorldTime(this);
  795. GetCurrentZone()->StartZoneInitialSpawnThread(this);
  796. }
  797. void Client::SendCharPOVGhost() {
  798. bool use_ghost_pov = false;
  799. PacketStruct* set_pov = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  800. int32 ghost_id = 0;
  801. if (set_pov) {
  802. if(pov_ghost_spawn_id) {
  803. Spawn* spawn = GetCurrentZone()->GetSpawnByID(pov_ghost_spawn_id);
  804. ghost_id = player->GetIDWithPlayerSpawn(spawn);
  805. if(spawn) {
  806. use_ghost_pov = true;
  807. }
  808. }
  809. if(use_ghost_pov) {
  810. set_pov->setDataByName("spawn_id", ghost_id);
  811. }
  812. else {
  813. set_pov->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  814. }
  815. EQ2Packet* app_pov = set_pov->serialize();
  816. QueuePacket(app_pov);
  817. safe_delete(set_pov);
  818. }
  819. }
  820. void Client::SendZoneInfo() {
  821. ZoneServer* zone = GetCurrentZone();
  822. if (zone) {
  823. EQ2Packet* packet = zone->GetZoneInfoPacket(this);
  824. QueuePacket(packet);
  825. if (version > 561) {
  826. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  827. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  828. #if EQDEBUG >= 9
  829. fog_packet->PrintPacket();
  830. #endif
  831. if (fog_packet) {
  832. database.LoadFogInit(zone->GetZoneFile(), fog_packet);
  833. QueuePacket(fog_packet->serialize());
  834. safe_delete(fog_packet);
  835. }
  836. zone->SendFlightPathsPackets(this);
  837. }
  838. }
  839. /*
  840. uchar blah[] ={0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x01,0x00,0x00,0x00,0x00
  841. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  842. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF
  843. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  844. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00
  845. ,0x00,0x00,0x00,0x00,0x10,0x49,0x2B,0x62,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  846. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  847. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  848. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  849. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  850. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  851. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  852. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  853. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  854. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  855. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  856. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  857. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  858. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  859. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  860. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  861. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  862. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  863. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  864. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  865. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  866. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  867. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  868. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  869. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  870. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  871. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  872. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  873. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  874. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  875. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00};
  876. EQ2Packet* appA = new EQ2Packet(OP_GuildUpdateMsg, blah, sizeof(blah));
  877. QueuePacket(appA);
  878. uchar blahA[] ={0x45,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00
  879. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  880. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  881. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00
  882. ,0x00,0x10,0xE2,0x10,0x6C,0x00,0x00,0x00,0x00};
  883. EQ2Packet* appB = new EQ2Packet(OP_KeymapDataMsg, blahA, sizeof(blahA));
  884. QueuePacket(appB);
  885. */
  886. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendFriendList");
  887. SendFriendList();
  888. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendIgnoreList");
  889. SendIgnoreList();
  890. }
  891. void Client::SendDefaultGroupOptions() {
  892. /*
  893. 0 - loot method
  894. 1 - loot items rarity
  895. 2 - Auto split coin
  896. 4 - default yell method
  897. 6 - group autolock
  898. 7 - solo autolock
  899. */
  900. PacketStruct* default_options = configReader.getStruct("WS_DefaultGroupOptions", GetVersion());
  901. if (default_options) {
  902. default_options->setDataByName("loot_method", GetPlayer()->GetInfoStruct()->get_group_loot_method());
  903. default_options->setDataByName("loot_items_rarity", GetPlayer()->GetInfoStruct()->get_group_loot_items_rarity());
  904. default_options->setDataByName("auto_split_coin", GetPlayer()->GetInfoStruct()->get_group_auto_split());
  905. default_options->setDataByName("default_yell_method", GetPlayer()->GetInfoStruct()->get_group_default_yell());
  906. default_options->setDataByName("group_autolock", GetPlayer()->GetInfoStruct()->get_group_autolock());
  907. default_options->setDataByName("default_group_lock_method", GetPlayer()->GetInfoStruct()->get_group_lock_method());
  908. if(GetVersion() > 561) {
  909. default_options->setDataByName("solo_autolock", GetPlayer()->GetInfoStruct()->get_group_solo_autolock());
  910. default_options->setDataByName("auto_loot_method", GetPlayer()->GetInfoStruct()->get_group_auto_loot_method());
  911. }
  912. EQ2Packet* app7 = default_options->serialize();
  913. QueuePacket(app7);
  914. safe_delete(default_options);
  915. }
  916. }
  917. bool Client::HandlePacket(EQApplicationPacket* app) {
  918. bool ret = true;
  919. //cout << "INCOMING PACKET!!!!!!!: " << app->GetOpcodeName() << endl;
  920. //DumpPacket(app);
  921. #if EQDEBUG >= 9
  922. LogWrite(PACKET__DEBUG, 9, "Packet", "[EQDEBUG] Received Packet:");
  923. DumpPacket(app, true);
  924. #endif
  925. EmuOpcode opcode = app->GetOpcode();
  926. #if EQDEBUG >= 9
  927. const char* name = app->GetOpcodeName();
  928. if (name)
  929. cout << name;
  930. else
  931. cout << "Unknown";
  932. cout << " Packet: OPCode: 0x" << hex << setw(2) << setfill('0') << app->GetOpcode() << dec << ", size: " << setw(5) << setfill(' ') << app->Size() << endl;
  933. DumpPacket(app);
  934. #endif
  935. //if (opcode != OP_UpdatePositionMsg) {
  936. // LogWrite(PACKET__DEBUG, 0, "opcode %s received", app->GetOpcodeName());
  937. //}
  938. if (!connected_to_zone && opcode != OP_LoginByNumRequestMsg)
  939. {
  940. opcode = _maxEmuOpcode; // skip since this is not a valid packet, sent before we allowed the login
  941. }
  942. switch (opcode) {
  943. case _maxEmuOpcode:
  944. break;
  945. case OP_LoginByNumRequestMsg: {
  946. LogWrite(OPCODE__DEBUG, 0, "Opcode", "Opcode 0x%X (%i): OP_LoginByNumRequestMsg", opcode, opcode);
  947. PacketStruct* request;
  948. request = configReader.getStruct("LoginByNumRequest", 1);
  949. if (request) {
  950. if(request->LoadPacketData(app->pBuffer, app->size)) {
  951. // test the original location of Version for clients older than 1212
  952. version = request->getType_int16_ByName("version");
  953. if (version == 0 || version >= 1208 || EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  954. // must be new client data version method, re-fetch the packet
  955. safe_delete(request);
  956. request = configReader.getStruct("LoginByNumRequest", 1208);
  957. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  958. // Xinux suggests using an INT16 here. Our first new version = 57000
  959. version = request->getType_int16_ByName("version");
  960. }
  961. else {
  962. LogWrite(LOGIN__ERROR, 0, "Login", "Nasty Horrible things happening. Tell a dev asap! Version: %i", version);
  963. break;
  964. }
  965. }
  966. if (EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  967. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  968. ClientPacketFunctions::SendLoginDenied(this);
  969. /* reset version and protect server from trying to send packets out to a bad client
  970. ** cause of Dec 6th/Dec 7th 2023 crash
  971. ** Client::MakeSpawnChangePacket
  972. ** int16 opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd); <-- crashes pulling opcode with bad version
  973. */
  974. version = 546;
  975. ready_for_updates = false;
  976. ready_for_spawns = false;
  977. return false;
  978. }
  979. int32 account_id = request->getType_int32_ByName("account_id");
  980. int32 access_code = request->getType_int32_ByName("access_code");
  981. if (!HandleNewLogin(account_id, access_code))
  982. return false;
  983. }
  984. }
  985. safe_delete(request);
  986. break;
  987. }
  988. case OP_DefaultGroupOptionsMsg: {
  989. PacketStruct* packet = configReader.getStruct("WS_DefaultGroupOptions", GetVersion());
  990. if (packet) {
  991. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  992. packet->PrintPacket();
  993. int8 loot_method = packet->getType_int8_ByName("loot_method");
  994. int8 loot_items_rarity = packet->getType_int8_ByName("loot_items_rarity");
  995. int8 auto_split_coin = packet->getType_int8_ByName("auto_split_coin");
  996. int8 default_yell_method = packet->getType_int8_ByName("default_yell_method");
  997. int8 autolock = packet->getType_int8_ByName("group_autolock");
  998. int8 group_lock_method = packet->getType_int8_ByName("default_group_lock_method");
  999. int8 solo_autolock = packet->getType_int8_ByName("solo_autolock");
  1000. int8 auto_loot_method = 0;
  1001. if (GetVersion() > 561) {
  1002. auto_loot_method = packet->getType_int8_ByName("auto_loot_method");
  1003. if (auto_loot_method > AutoLootMode::METHOD_DECLINE)
  1004. auto_loot_method = AutoLootMode::METHOD_DECLINE;
  1005. }
  1006. GetPlayer()->GetInfoStruct()->set_group_loot_method(loot_method);
  1007. GetPlayer()->GetInfoStruct()->set_group_loot_items_rarity(loot_items_rarity);
  1008. GetPlayer()->GetInfoStruct()->set_group_auto_split(auto_split_coin);
  1009. GetPlayer()->GetInfoStruct()->set_group_default_yell(default_yell_method);
  1010. GetPlayer()->GetInfoStruct()->set_group_autolock(autolock);
  1011. GetPlayer()->GetInfoStruct()->set_group_lock_method(group_lock_method);
  1012. GetPlayer()->GetInfoStruct()->set_group_solo_autolock(solo_autolock);
  1013. GetPlayer()->GetInfoStruct()->set_group_auto_loot_method(auto_loot_method);
  1014. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPLOOTMETHOD, (char*)std::to_string(loot_method).c_str());
  1015. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPLOOTITEMRARITY, (char*)std::to_string(loot_items_rarity).c_str());
  1016. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPAUTOSPLIT, (char*)std::to_string(auto_split_coin).c_str());
  1017. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPDEFAULTYELL, (char*)std::to_string(default_yell_method).c_str());
  1018. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPAUTOLOCK, (char*)std::to_string(autolock).c_str());
  1019. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPLOCKMETHOD, (char*)std::to_string(group_lock_method).c_str());
  1020. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPSOLOAUTOLOCK, (char*)std::to_string(solo_autolock).c_str());
  1021. database.insertCharacterProperty(this, CHAR_PROPERTY_AUTOLOOTMETHOD, (char*)std::to_string(auto_loot_method).c_str());
  1022. if (this->GetPlayer()->GetGroupMemberInfo() && this->GetPlayer()->GetGroupMemberInfo()->leader)
  1023. {
  1024. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  1025. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  1026. if (group)
  1027. {
  1028. GroupOptions goptions;
  1029. goptions.loot_method = loot_method;
  1030. goptions.loot_items_rarity = loot_items_rarity;
  1031. goptions.auto_split = auto_split_coin;
  1032. goptions.default_yell = default_yell_method;
  1033. goptions.group_autolock = autolock;
  1034. goptions.solo_autolock = solo_autolock;
  1035. goptions.auto_loot_method = auto_loot_method;
  1036. group->SetDefaultGroupOptions(&goptions);
  1037. }
  1038. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  1039. }
  1040. }
  1041. safe_delete(packet);
  1042. }
  1043. break;
  1044. }
  1045. case OP_MapRequest: {
  1046. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapRequest", opcode, opcode);
  1047. PacketStruct* packet = configReader.getStruct("WS_MapRequest", GetVersion());
  1048. if (packet && app->size > 2 && GetCurrentZone()) {
  1049. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1050. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  1051. if (fog_packet) {
  1052. LogWrite(PACKET__DEBUG, 0, "Packet", "In OP_MapRequest: Fog Packet");
  1053. database.LoadFogInit(packet->getType_EQ2_16BitString_ByName("zone").data, fog_packet);
  1054. fog_packet->setDataByName("unknown1", 1);
  1055. fog_packet->setDataByName("unknown3", 1);
  1056. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1057. //fog_packet->PrintPacket();
  1058. QueuePacket(fog_packet->serialize());
  1059. safe_delete(fog_packet);
  1060. }
  1061. }
  1062. safe_delete(packet);
  1063. }
  1064. break;
  1065. }
  1066. case OP_RequestCampMsg: {
  1067. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RequestCampMsg", opcode, opcode);
  1068. PacketStruct* request = configReader.getStruct("WS_RequestCamp", GetVersion());
  1069. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  1070. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client '%s' (%u) is camping...", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  1071. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_RequestCamp - quit: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  1072. request->getType_int8_ByName("quit"),
  1073. request->getType_int8_ByName("camp_desktop"),
  1074. request->getType_int16_ByName("camp_char_select"),
  1075. (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? request->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  1076. //DumpPacket(app->pBuffer, app->size);
  1077. //request->PrintPacket();
  1078. if (!camp_timer) {
  1079. int16 camp_time = 20; // default if rule cannot be found
  1080. if (GetAdminStatus() >= 100)
  1081. camp_time = rule_manager.GetGlobalRule(R_World, GMCampTimer)->GetInt16();
  1082. else
  1083. camp_time = rule_manager.GetGlobalRule(R_World, PlayerCampTimer)->GetInt16();
  1084. PacketStruct* response = configReader.getStruct("WS_Camp", GetVersion());
  1085. if (response) {
  1086. bool disconnect = false;
  1087. if (request->getType_int8_ByName("camp_desktop") == 1 && request->getType_int8_ByName("quit") == 1) {
  1088. // Command: /camp desktop
  1089. // Command: /quit
  1090. response->setDataByName("camp_desktop", 1);
  1091. disconnect = true;
  1092. }
  1093. else {
  1094. // Command: /camp
  1095. response->setDataByName("camp_desktop", request->getType_int8_ByName("camp_desktop"));
  1096. response->setDataByName("camp_char_select", request->getType_int16_ByName("camp_char_select"));
  1097. response->setDataByName("seconds", camp_time);
  1098. }
  1099. camp_timer = new Timer(camp_time * 1000);
  1100. camp_timer->Enable();
  1101. if (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) {
  1102. // /camp {char_name}
  1103. response->setDataByName("char_name", request->getType_EQ2_16BitString_ByName("char_name").data.c_str());
  1104. }
  1105. else if (request->getType_int8_ByName("camp_desktop") == 0 && request->getType_int16_ByName("camp_char_select") == 0) {
  1106. // /camp (go back to char selection screen)
  1107. response->setDataByName("char_name", " ");
  1108. response->setDataByName("camp_char_select", 1);
  1109. }
  1110. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_Camp - seconds: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  1111. response->getType_int8_ByName("seconds"),
  1112. response->getType_int8_ByName("camp_desktop"),
  1113. response->getType_int8_ByName("camp_char_select"),
  1114. (response->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? response->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  1115. // JA: trying to recognize /camp vs LD (see ZoneServer::ClientProcess())
  1116. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0)
  1117. player->SetActivityStatus(player->GetActivityStatus() + ACTIVITY_STATUS_CAMPING);
  1118. //response->PrintPacket();
  1119. QueuePacket(response->serialize());
  1120. safe_delete(response);
  1121. if (disconnect)
  1122. Disconnect();
  1123. }
  1124. }
  1125. }
  1126. safe_delete(request);
  1127. break;
  1128. }
  1129. case OP_StoodMsg: {
  1130. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StoodMsg", opcode, opcode);
  1131. if (camp_timer)
  1132. {
  1133. // JA: clear camping flag
  1134. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1135. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1136. safe_delete(camp_timer);
  1137. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1138. QueuePacket(outapp);
  1139. }
  1140. player->SetTempVisualState(0);
  1141. break;
  1142. }
  1143. case OP_StandMsg: {
  1144. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StandMsg", opcode, opcode);
  1145. if (camp_timer)
  1146. {
  1147. // JA: clear camping flag
  1148. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1149. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1150. safe_delete(camp_timer);
  1151. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1152. QueuePacket(outapp);
  1153. }
  1154. player->SetTempVisualState(539);
  1155. break;
  1156. }
  1157. case OP_SitMsg: {
  1158. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SitMsg", opcode, opcode);
  1159. player->SetTempVisualState(538);
  1160. break;
  1161. }
  1162. case OP_SatMsg: {
  1163. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SatMsg", opcode, opcode);
  1164. player->SetTempVisualState(540);
  1165. break;
  1166. }
  1167. case OP_QuestJournalOpenMsg:
  1168. case OP_QuestJournalInspectMsg: {
  1169. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalOpenMsg, OP_QuestJournalInspectMsg", opcode, opcode);
  1170. if (app->size < sizeof(int32))
  1171. break;
  1172. int32 quest_id = 0;
  1173. memcpy(&quest_id, app->pBuffer, sizeof(int32));
  1174. GetPlayer()->SendQuest(quest_id);
  1175. break;
  1176. }
  1177. case OP_QuestJournalSetVisibleMsg: {
  1178. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalSetVisibleMsg", opcode, opcode);
  1179. PacketStruct* packet = configReader.getStruct("WS_QuestJournalVisible", GetVersion());
  1180. if (packet) {
  1181. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1182. int32 quest_id = packet->getType_int32_ByName("quest_id");
  1183. bool hidden = packet->getType_int8_ByName("visible") == 1 ? false : true;
  1184. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  1185. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  1186. if (player_quests) {
  1187. if (player_quests->count(quest_id) > 0)
  1188. player_quests->at(quest_id)->SetHidden(hidden);
  1189. else
  1190. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Player does not have quest with id of %u", quest_id);
  1191. }
  1192. else
  1193. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Unable to get player(%s) quests", player->GetName());
  1194. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  1195. }
  1196. safe_delete(packet);
  1197. }
  1198. break;
  1199. }
  1200. case OP_MacroUpdateMsg: {
  1201. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MacroUpdateMsg", opcode, opcode);
  1202. PacketStruct* macro_update = configReader.getStruct("WS_MacroUpdate", GetVersion());
  1203. if (macro_update) {
  1204. if(macro_update->LoadPacketData(app->pBuffer, app->size)) {
  1205. vector<string>* update = new vector<string>;
  1206. int8 number = macro_update->getType_int8_ByName("number");
  1207. int16 icon = macro_update->getType_int16_ByName("icon");
  1208. string name = macro_update->getType_EQ2_8BitString_ByName("name").data;
  1209. int8 count = macro_update->getType_int8_ByName("macro_count");
  1210. if (GetVersion() <= 373) {
  1211. update->push_back(macro_update->getType_EQ2_8BitString_ByName("command").data);
  1212. }
  1213. else {
  1214. for (int8 i = 0; i < count; i++) {
  1215. char tmp_command[15] = { 0 };
  1216. sprintf(tmp_command, "command_%i", i);
  1217. update->push_back(macro_update->getType_EQ2_16BitString_ByName(tmp_command).data);
  1218. }
  1219. }
  1220. if (name.length() == 0)
  1221. database.UpdateCharacterMacro(GetCharacterID(), number, 0, icon, update);
  1222. else
  1223. database.UpdateCharacterMacro(GetCharacterID(), number, name.c_str(), icon, update);
  1224. safe_delete(update);
  1225. }
  1226. safe_delete(macro_update);
  1227. }
  1228. break;
  1229. }
  1230. case OP_DialogSelectMsg: {
  1231. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DialogSelectMsg", opcode, opcode);
  1232. PacketStruct* packet = configReader.getStruct("WS_DialogSelect", GetVersion());
  1233. if (packet) {
  1234. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1235. int32 conversation_id = packet->getType_int32_ByName("conversation_id");
  1236. int32 response_index = packet->getType_int32_ByName("response");
  1237. HandleDialogSelectMsg(conversation_id, response_index);
  1238. }
  1239. }
  1240. safe_delete(packet);
  1241. break;
  1242. }
  1243. case OP_CancelMoveObjectModeMsg: {
  1244. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1245. if (GetTempPlacementSpawn())
  1246. {
  1247. Spawn* tmp = GetTempPlacementSpawn();
  1248. SetTempPlacementSpawn(nullptr);
  1249. SetPlacementUniqueItemID(0);
  1250. GetCurrentZone()->RemoveSpawn(tmp, true, false, true, true, true);
  1251. break; // break out early if we are tied to a temp spawn
  1252. }
  1253. // if we are moving some other object? other use-cases not covered
  1254. break;
  1255. }
  1256. case OP_PositionMoveableObject: {
  1257. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PositionMoveableObject", opcode, opcode);
  1258. PacketStruct* place_object = configReader.getStruct("WS_PlaceMoveableObject", GetVersion());
  1259. if (place_object && place_object->LoadPacketData(app->pBuffer, app->size)) {
  1260. Spawn* spawn = 0;
  1261. if (GetTempPlacementSpawn())
  1262. spawn = GetTempPlacementSpawn();
  1263. else
  1264. spawn = GetPlayer()->GetSpawnWithPlayerID(place_object->getType_int32_ByName("spawn_id"));
  1265. if (!spawn) {
  1266. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn.");
  1267. break;
  1268. }
  1269. else if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE && !HasOwnerOrEditAccess())
  1270. {
  1271. SimpleMessage(CHANNEL_COLOR_RED, "This is not your home!");
  1272. break;
  1273. }
  1274. int32 uniqueID = spawn->GetPickupUniqueItemID();
  1275. if(uniqueID) {
  1276. Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  1277. if(uniqueItem && uniqueItem->CheckFlag2(HOUSE_LORE) && GetCurrentZone()->HouseItemSpawnExists(uniqueItem->details.item_id)) {
  1278. Message(CHANNEL_COLOR_RED, "Item %s is house lore and you cannot place another.", uniqueItem->name.c_str());
  1279. break;
  1280. }
  1281. }
  1282. // handles instantiation logic + adding to zone of a new house object
  1283. PopulateHouseSpawn(place_object);
  1284. float newHeading = place_object->getType_float_ByName("heading") + 180;
  1285. char query[256];
  1286. switch (GetSpawnPlacementMode())
  1287. {
  1288. case ServerSpawnPlacementMode::OPEN_HEADING:
  1289. {
  1290. if (spawn && spawn->IsWidget())
  1291. {
  1292. Widget* widget = (Widget*)spawn;
  1293. widget->SetOpenHeading(newHeading);
  1294. widget->SetIncludeHeading(true);
  1295. spawn->position_changed = true;
  1296. _snprintf(query, 256, "open_heading=%f,include_heading=1", newHeading);
  1297. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1298. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget open heading information.");
  1299. }
  1300. else
  1301. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1302. break;
  1303. }
  1304. case ServerSpawnPlacementMode::CLOSE_HEADING:
  1305. {
  1306. if (spawn && spawn->IsWidget())
  1307. {
  1308. Widget* widget = (Widget*)spawn;
  1309. widget->SetClosedHeading(newHeading);
  1310. widget->SetIncludeHeading(true);
  1311. spawn->position_changed = true;
  1312. _snprintf(query, 256, "closed_heading=%f,include_heading=1", newHeading);
  1313. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1314. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget close heading information.");
  1315. if (spawn->GetSpawnLocationID())
  1316. {
  1317. Query query;
  1318. query.RunQuery2(Q_INSERT, "update spawn_location_placement set heading = %f where id = %u", newHeading, spawn->GetSpawnLocationID());
  1319. }
  1320. }
  1321. else
  1322. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1323. break;
  1324. }
  1325. default:
  1326. {
  1327. spawn->SetX(place_object->getType_float_ByName("x"));
  1328. spawn->SetY(place_object->getType_float_ByName("y"));
  1329. spawn->SetZ(place_object->getType_float_ByName("z"));
  1330. spawn->SetHeading(newHeading);
  1331. spawn->SetSpawnOrigX(spawn->GetX());
  1332. spawn->SetSpawnOrigY(spawn->GetY());
  1333. spawn->SetSpawnOrigZ(spawn->GetZ());
  1334. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1335. if (spawn->GetSpawnLocationID() > 0 && database.UpdateSpawnLocationSpawns(spawn))
  1336. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved spawn information.");
  1337. else if (spawn->GetSpawnLocationID() > 0)
  1338. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn information, see console window for details.");
  1339. }
  1340. }
  1341. PopulateHouseSpawnFinalize();
  1342. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1343. }
  1344. safe_delete(place_object);
  1345. break;
  1346. }
  1347. case OP_CampAbortedMsg: {
  1348. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CampAbortedMsg", opcode, opcode);
  1349. if (camp_timer)
  1350. {
  1351. // JA: clear camping flag
  1352. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1353. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1354. safe_delete(camp_timer);
  1355. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1356. QueuePacket(outapp);
  1357. }
  1358. break;
  1359. }
  1360. case OP_DoneLoadingUIResourcesMsg: {
  1361. if(GetVersion() <= 561) {
  1362. ClientPacketFunctions::SendUpdateSpellBook(this);
  1363. }
  1364. // need to quickly flash the DoF client the rest of their inventory
  1365. if(GetVersion() <= 561) {
  1366. EQ2Packet* item_app = player->GetPlayerItemList()->serialize(GetPlayer(), GetVersion());
  1367. if (item_app) {
  1368. QueuePacket(item_app);
  1369. }
  1370. }
  1371. EQ2Packet* app = new EQ2Packet(OP_DoneLoadingUIResourcesMsg, 0, 0);
  1372. QueuePacket(app);
  1373. if(!player_loading_complete)
  1374. {
  1375. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  1376. if (zone_script && lua_interface)
  1377. lua_interface->RunZoneScript(zone_script, "player_loadcomplete", GetCurrentZone(), GetPlayer());
  1378. player_loading_complete = true;
  1379. }
  1380. break;
  1381. }
  1382. case OP_DoneLoadingZoneResourcesMsg: {
  1383. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingZoneResourcesMsg", opcode, opcode);
  1384. SendZoneSpawns();
  1385. break;
  1386. }
  1387. case OP_DefaultGroupOptionsRequestMsg: {
  1388. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DefaultGroupOptionsRequestMsg", opcode, opcode);
  1389. SendDefaultGroupOptions();
  1390. break;
  1391. }
  1392. case OP_DoneLoadingEntityResourcesMsg: {
  1393. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingEntityResourcesMsg", opcode, opcode);
  1394. if (!IsReadyForSpawns())
  1395. SetReadyForSpawns(true);
  1396. player->CalculateApplyWeight();
  1397. SendCharInfo();
  1398. GetPlayer()->GetZone()->GetSpellProcess()->SendSpellBookUpdate(this);
  1399. pos_update.Start();
  1400. quest_pos_timer.Start();
  1401. break;
  1402. }
  1403. case OP_LootItemsRequestMsg: {
  1404. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_LootItemsRequestMsg", opcode, opcode);
  1405. HandleLootItemRequestPacket(app);
  1406. break;
  1407. }
  1408. case OP_StoppedLootingMsg: {
  1409. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StoppedLootingMsg", opcode, opcode);
  1410. if (app->size < sizeof(int32))
  1411. break;
  1412. int32 loot_id = 0;
  1413. memcpy(&loot_id, app->pBuffer, sizeof(int32));
  1414. Spawn* spawn = GetCurrentZone()->GetSpawnByID(loot_id);
  1415. if(spawn) {
  1416. spawn->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
  1417. spawn->SetLooterSpawnID(0);
  1418. }
  1419. break;
  1420. }
  1421. case OP_WaypointSelectMsg: {
  1422. PacketStruct* packet = configReader.getStruct("WS_WaypointSelect", GetVersion());
  1423. if (packet) {
  1424. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1425. int32 selection = packet->getType_int32_ByName("selection");
  1426. if (selection > 0) {
  1427. SelectWaypoint(selection);
  1428. }
  1429. }
  1430. }
  1431. safe_delete(packet);
  1432. break;
  1433. }
  1434. case OP_KnowledgeWindowSlotMappingMsg: {
  1435. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_KnowledgeWindowSlotMappingMsg", opcode, opcode);
  1436. PacketStruct* packet = configReader.getStruct("WS_SpellSlotMapping", GetVersion());
  1437. if (packet) {
  1438. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1439. int num_updates = packet->getType_int16_ByName("spell_count");
  1440. int32 spell_id = 0;
  1441. int16 slot_id = 0;
  1442. char tmp_spell_id[15];
  1443. char tmp_slot[15];
  1444. for (int i = 0; i < num_updates; i++) {
  1445. memset(tmp_spell_id, 0, 15);
  1446. memset(tmp_slot, 0, 15);
  1447. sprintf(tmp_spell_id, "spell_id_%i", i);
  1448. sprintf(tmp_slot, "slot_id_%i", i);
  1449. spell_id = packet->getType_int32_ByName(tmp_spell_id);
  1450. if (spell_id > 0) {
  1451. slot_id = packet->getType_int16_ByName(tmp_slot);
  1452. SpellBookEntry* spell = player->GetSpellBookSpell(spell_id);
  1453. if (spell && spell->slot != slot_id) {
  1454. spell->slot = slot_id;
  1455. spell->save_needed = true;
  1456. }
  1457. }
  1458. }
  1459. }
  1460. safe_delete(packet);
  1461. }
  1462. //SendKnowledgeWindowSlot();
  1463. break;
  1464. }
  1465. case OP_ReadyToZoneMsg: {
  1466. if (!IsReadyForSpawns())
  1467. {
  1468. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s is logging into zone, skipping disconnect.");
  1469. }
  1470. else
  1471. {
  1472. if(zoning_destination) {
  1473. SetCurrentZone(zoning_destination);
  1474. }
  1475. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyToZoneMsg", opcode, opcode);
  1476. bool succeed_override_zone = true;
  1477. if(!GetCurrentZone()) {
  1478. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone and zone is not there! Emergency boot!", player->GetName());
  1479. if(zoning_instance_id) {
  1480. ZoneServer* zone = zone_list.GetByInstanceID(zoning_instance_id, zoning_id, true);
  1481. if(!zone) {
  1482. 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);
  1483. succeed_override_zone = false;
  1484. }
  1485. else {
  1486. SetCurrentZone(zone);
  1487. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Unique instance has been created for %s through emergency boot!", player->GetName());
  1488. }
  1489. }
  1490. else if(zoning_id) {
  1491. ZoneServer* zone = zone_list.Get(zoning_id, true, true);
  1492. if(!zone) {
  1493. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Emergency boot failed for %s, unable to get zoneserver zone id %u.", player->GetName(), zoning_id);
  1494. succeed_override_zone = false;
  1495. }
  1496. else {
  1497. SetCurrentZone(zone);
  1498. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Unique zone has been created for %s through emergency boot!", player->GetName());
  1499. }
  1500. }
  1501. }
  1502. if (client_zoning)
  1503. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s zoning to %s", player->GetName(), GetCurrentZone()->GetZoneName());
  1504. else
  1505. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone without server authorization.", player->GetName());
  1506. Disconnect();
  1507. }
  1508. break;
  1509. }
  1510. case OP_ClientFellMsg: {
  1511. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ClientFellMsg (ouch!)", opcode, opcode);
  1512. PacketStruct* request = configReader.getStruct("WS_ClientFell", GetVersion());
  1513. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  1514. float height = request->getType_float_ByName("height");
  1515. /*int32 spawn_id = request->getType_int32_ByName("spawn_id");
  1516. if(GetPlayer()->GetSpawnWithPlayerID(spawn_id) != GetPlayer()){
  1517. cout << "Error: " << GetPlayer()->GetName() << " called ClientFell with an invalid ID of: " << spawn_id << endl;
  1518. break;
  1519. }*/
  1520. float safe_height = 13.0f;
  1521. float safe_skill_with_bonus = GetPlayer()->CalculateSkillWithBonus("Safe Fall", ITEM_STAT_SAFE_FALL, true);
  1522. if (safe_skill_with_bonus > 0.0f)
  1523. safe_height += (1 + safe_skill_with_bonus) / 5;
  1524. if (height > safe_height) {
  1525. int16 damage = (int16)ceil((height - safe_height) * 125);
  1526. if (height >= 80)
  1527. damage = 30000;
  1528. //cout << "Detected fall height:" << height << " damage:" << damage << endl;
  1529. if (damage > 0) {
  1530. GetPlayer()->TakeDamage(damage);
  1531. if (GetPlayer()->GetPlayerStatisticValue(STAT_PLAYER_HIGHEST_FALLING_HIT) < damage)
  1532. GetPlayer()->UpdatePlayerStatistic(STAT_PLAYER_HIGHEST_FALLING_HIT, damage, true);
  1533. if (!GetPlayer()->GetInvulnerable())
  1534. GetPlayer()->SetCharSheetChanged(true);
  1535. 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);
  1536. if (GetPlayer()->GetHP() == 0) {
  1537. GetCurrentZone()->KillSpawn(false, GetPlayer(), 0);
  1538. }
  1539. }
  1540. }
  1541. }
  1542. safe_delete(request);
  1543. break;
  1544. }
  1545. case OP_MapFogDataUpdateMsg: {
  1546. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapFogDataUpdateMsg", opcode, opcode);
  1547. LogWrite(MISC__TODO, 3, "TODO", "Handle (OP_MapFogDataUpdateMsg), ignoring it for now\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1548. break;
  1549. }
  1550. case OP_SelectZoneTeleporterDestinatio: {
  1551. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SelectZoneTeleporterDestinatio", opcode, opcode);
  1552. ProcessTeleportLocation(app);
  1553. break;
  1554. }
  1555. case OP_SendLatestRequestMsg: {
  1556. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SendLatestRequestMsg", opcode, opcode);
  1557. if(GetVersion() < 60085) {
  1558. // this does not exist in newer clients like AoM, confirmed to exist in DoF, other clients will need review at a later time
  1559. uchar blah25[] = { 0x01 };
  1560. EQ2Packet* app25 = new EQ2Packet(OP_ClearDataMsg, blah25, sizeof(blah25));
  1561. QueuePacket(app25);
  1562. }
  1563. break;
  1564. }
  1565. case OP_RequestRecipeDetailsMsg: {
  1566. PacketStruct* packet = configReader.getStruct("WS_RequestRecipeDetail", GetVersion());
  1567. if (packet) {
  1568. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1569. vector<int32> recipes;
  1570. int32 recipe_id = 0;
  1571. char recipe_prop_name[30];
  1572. int32 num_recipes = packet->getType_int32_ByName("num_recipes");
  1573. // WS_RecipeDetails
  1574. for (int32 i = 0; i < num_recipes; i++) {
  1575. memset(recipe_prop_name, 0, 30);
  1576. snprintf(recipe_prop_name, 30, "recipe_id_%i", i);
  1577. recipe_id = packet->getType_int32_ByName(recipe_prop_name);
  1578. if(recipe_id > 0) {
  1579. recipes.push_back(recipe_id);
  1580. }
  1581. }
  1582. SendRecipeDetails(&recipes);
  1583. }
  1584. safe_delete(packet);
  1585. }
  1586. break;
  1587. }
  1588. case OP_ShowCreateFromRecipeUIMsg: {
  1589. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ShowCreateFromRecipeUIMsg", opcode, opcode);
  1590. break;
  1591. /*uchar blah[] ={0x09,0x0e,0x00,0x51,0x75,0x65,0x65,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e
  1592. ,0x79,0x00,0x00,0x00,0x00,0x40,0x40,0xff,0xff,0xff};
  1593. EQ2Packet* app = new EQ2Packet(OP_EncounterBrokenMsg, blah, sizeof(blah));
  1594. QueuePacket(app);
  1595. uchar blah2[] = {0x00,0x00,0xff,0xff,0xff,0xff};
  1596. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah2, sizeof(blah2));
  1597. QueuePacket(app);
  1598. uchar blah3[] ={0x09,0x17,0x00,0x5c,0x23,0x46,0x46,0x45,0x34,0x30,0x30,0x20,0x51,0x75,0x65,0x65
  1599. ,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e,0x79,0x00,0x00,0x00,0x00,0xa0,0x40
  1600. ,0xff,0xff,0xff};
  1601. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah3, sizeof(blah3));
  1602. QueuePacket(app);
  1603. uchar blah4[] ={0x0b,0x00,0x21,0x00,0x00,0x00,0x1d,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17
  1604. ,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81
  1605. ,0x42,0x17,0x81,0x42,0x17,0x81,0x42};
  1606. app = new EQ2Packet(OP_UpdateSpellBookMsg, blah4, sizeof(blah4));
  1607. QueuePacket(app);
  1608. uchar blah5[] ={0x00,0x00};
  1609. app = new EQ2Packet(OP_RecipeDetailsMsg, blah5, sizeof(blah5));
  1610. QueuePacket(app);
  1611. break;*/
  1612. //player->GetPlayerInfo()->GetInfo()->cur_power = 100;
  1613. //EQ2Packet* app = player->GetPlayerInfo()->serialize(1);
  1614. //QueuePacket(app);
  1615. }
  1616. case OP_BeginItemCreationMsg: {
  1617. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginItemCreationMsg", opcode, opcode);
  1618. //DumpPacket(app->pBuffer, app->size);
  1619. PacketStruct* packet = configReader.getStruct("WS_BeginItemCreation", GetVersion());
  1620. if (packet) {
  1621. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1622. int32 item = 0;
  1623. int8 qty = 0;
  1624. vector<pair<int32, int16>> items;
  1625. char tmp_item_id[30];
  1626. int8 num_primary_selected_items = packet->getType_int8_ByName("num_primary_selected_items");
  1627. for (int8 i = 0; i < num_primary_selected_items; i++) {
  1628. memset(tmp_item_id, 0, 30);
  1629. sprintf(tmp_item_id, "primary_selected_item_id_%i", i);
  1630. item = packet->getType_int32_ByName(tmp_item_id);
  1631. sprintf(tmp_item_id, "primary_selected_item_qty_%i", i);
  1632. qty = packet->getType_int16_ByName(tmp_item_id);
  1633. if (item > 0)
  1634. items.push_back(make_pair(item,qty));
  1635. item = 0;
  1636. }
  1637. int8 build_components = packet->getType_int8_ByName("num_build_components");
  1638. for (int8 i = 0; i < build_components; i++) {
  1639. memset(tmp_item_id, 0, 30);
  1640. sprintf(tmp_item_id, "num_selected_items_%i", i);
  1641. int8 num_selected_items = packet->getType_int8_ByName(tmp_item_id);
  1642. for (int8 j = 0; j < num_selected_items; j++) {
  1643. memset(tmp_item_id, 0, 30);
  1644. sprintf(tmp_item_id, "selected_id%i_%i", i,j);
  1645. item = packet->getType_int32_ByName(tmp_item_id);
  1646. sprintf(tmp_item_id, "selected_qty%i_%i", i, j);
  1647. qty = packet->getType_int16_ByName(tmp_item_id);
  1648. if (item > 0)
  1649. items.push_back(make_pair(item, qty));
  1650. item = 0;
  1651. }
  1652. }
  1653. int8 num_fuel_items = packet->getType_int8_ByName("num_fuel_items");
  1654. for (int8 i = 0; i < num_fuel_items; i++) {
  1655. memset(tmp_item_id, 0, 30);
  1656. sprintf(tmp_item_id, "fuel_id_%i", i);
  1657. item = packet->getType_int32_ByName(tmp_item_id);
  1658. sprintf(tmp_item_id, "fuel_qty_%i", i);
  1659. qty = packet->getType_int16_ByName(tmp_item_id);
  1660. if (item > 0)
  1661. items.push_back(make_pair(item, qty));
  1662. item = 0;
  1663. }
  1664. GetCurrentZone()->GetTradeskillMgr()->BeginCrafting(this, items);
  1665. }
  1666. safe_delete(packet);
  1667. }
  1668. break;
  1669. }
  1670. case OP_StopItemCreationMsg: {
  1671. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopItemCreationMsg", opcode, opcode);
  1672. //DumpPacket(app->pBuffer, app->size);
  1673. GetCurrentZone()->GetTradeskillMgr()->StopCrafting(this);
  1674. break;
  1675. }
  1676. case OP_SysClient:
  1677. case OP_SignalMsg: {
  1678. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SysClient/OP_SignalMsg", opcode, opcode);
  1679. PacketStruct* packet = configReader.getStruct("WS_Signal", 1);
  1680. if (packet) {
  1681. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1682. EQ2_16BitString str = packet->getType_EQ2_16BitString_ByName("signal");
  1683. if (strcmp(str.data.c_str(), "sys_client_avatar_ready") == 0) {
  1684. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client '%s' (%u) is ready for spawn updates.", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  1685. SetReloadingZone(false);
  1686. if(GetPlayer()->IsDeletedSpawn()) {
  1687. GetPlayer()->SetDeletedSpawn(false);
  1688. }
  1689. ResetZoningCoords();
  1690. SetReadyForUpdates();
  1691. GetPlayer()->SendSpawnChanges(true);
  1692. ProcessStateCommands();
  1693. GetPlayer()->changed = true;
  1694. GetPlayer()->info_changed = true;
  1695. GetPlayer()->vis_changed = true;
  1696. player_pos_changed = true;
  1697. GetPlayer()->AddChangedZoneSpawn();
  1698. ProcessZoneIgnoreWidgets();
  1699. if (version <= 561) {
  1700. master_trait_list.ChooseNextTrait(this);
  1701. }
  1702. if (GetPlayer()->GetHP() < GetPlayer()->GetTotalHP() || GetPlayer()->GetPower() < GetPlayer()->GetTotalPower())
  1703. GetCurrentZone()->AddDamagedSpawn(GetPlayer());
  1704. }
  1705. else {
  1706. LogWrite(CCLIENT__WARNING, 0, "Client", "Player %s reported SysClient/SignalMsg state %s.", GetPlayer()->GetName(), str.data.c_str());
  1707. }
  1708. const char* zone_script = world.GetZoneScript(player->GetZone()->GetZoneID());
  1709. if (zone_script && lua_interface)
  1710. {
  1711. lua_interface->RunZoneScript(zone_script, "signal_changed", player->GetZone(), player, 0, str.data.c_str());
  1712. }
  1713. }
  1714. safe_delete(packet);
  1715. }
  1716. break;
  1717. }
  1718. case OP_EntityVerbsRequestMsg: {
  1719. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsRequestMsg", opcode, opcode);
  1720. HandleVerbRequest(app);
  1721. break;
  1722. }
  1723. case OP_EntityVerbsVerbMsg: {
  1724. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsVerbMsg", opcode, opcode);
  1725. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsVerb", GetVersion());
  1726. if (packet) {
  1727. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1728. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1729. player->SetTarget(player->GetSpawnWithPlayerID(spawn_id));
  1730. Spawn* spawn = player->GetTarget();
  1731. if (spawn && !spawn->IsNPC() && !spawn->IsPlayer()) {
  1732. string command = packet->getType_EQ2_16BitString_ByName("command").data;
  1733. if (!HandleHouseEntityCommands(spawn, spawn_id, command))
  1734. {
  1735. if (EntityCommandPrecheck(spawn, command.c_str())) {
  1736. if (spawn->IsGroundSpawn())
  1737. ((GroundSpawn*)spawn)->HandleUse(this, command);
  1738. else if (spawn->IsObject())
  1739. ((Object*)spawn)->HandleUse(this, command);
  1740. else if (spawn->IsWidget())
  1741. ((Widget*)spawn)->HandleUse(this, command);
  1742. else if (spawn->IsSign())
  1743. ((Sign*)spawn)->HandleUse(this, command);
  1744. }
  1745. }
  1746. }
  1747. else {
  1748. EQ2_16BitString command = packet->getType_EQ2_16BitString_ByName("command");
  1749. if (command.size > 0) {
  1750. string command_name = command.data;
  1751. if (command_name.find(" ") < 0xFFFFFFFF) {
  1752. if (GetVersion() <= 561) { //this version uses commands in the form "Buy From Merchant" instead of buy_from_merchant
  1753. string::size_type pos = command_name.find(" ");
  1754. while(pos != string::npos){
  1755. command_name.replace(pos, 1, "_");
  1756. pos = command_name.find(" ");
  1757. }
  1758. }
  1759. else
  1760. command_name = command_name.substr(0, command_name.find(" "));
  1761. }
  1762. int32 handler = commands.GetCommandHandler(command_name.c_str());
  1763. if (handler != 0xFFFFFFFF) {
  1764. if (command.data == command_name) {
  1765. command.data = "";
  1766. command.size = 0;
  1767. }
  1768. else {
  1769. command.data = command.data.substr(command.data.find(" ") + 1);
  1770. command.size = command.data.length();
  1771. }
  1772. commands.Process(handler, &command, this);
  1773. }
  1774. else {
  1775. if (spawn && spawn->IsNPC()) {
  1776. if (EntityCommandPrecheck(spawn, command.data.c_str())) {
  1777. if (!((NPC*)spawn)->HandleUse(this, command.data)) {
  1778. command_name = command.data;
  1779. string::size_type pos = command_name.find(" ");
  1780. while (pos != string::npos) {
  1781. command_name.replace(pos, 1, "_");
  1782. pos = command_name.find(" ");
  1783. }
  1784. if (!((NPC*)spawn)->HandleUse(this, command_name)) { //convert the spaces to underscores and see if that makes a difference
  1785. LogWrite(WORLD__ERROR, 0, "World", "Unhandled command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1786. }
  1787. }
  1788. }
  1789. }
  1790. else
  1791. LogWrite(WORLD__ERROR, 0, "World", "Unknown command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1792. }
  1793. }
  1794. }
  1795. }
  1796. safe_delete(packet);
  1797. }
  1798. break;
  1799. }
  1800. case OP_SkillInfoRequest: {
  1801. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SkillInfoRequest", opcode, opcode);
  1802. HandleSkillInfoRequest(app);
  1803. break;
  1804. }
  1805. case OP_UpdateTargetMsg: {
  1806. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_UpdateTargetMsg", opcode, opcode);
  1807. int16 index = 0;
  1808. memcpy(&index, app->pBuffer, sizeof(int16));
  1809. if (index == 0xFFFF)
  1810. GetPlayer()->SetTarget(0);
  1811. else {
  1812. Spawn* spawn = GetPlayer()->GetSpawnByIndex(index);
  1813. if(spawn)
  1814. GetPlayer()->SetTarget(spawn);
  1815. else {
  1816. LogWrite(PLAYER__ERROR, 1, "Player", "Player %s tried to target %u index, but that index was not valid.", GetPlayer()->GetName(), index);
  1817. }
  1818. }
  1819. if (GetPlayer()->GetTarget())
  1820. GetCurrentZone()->CallSpawnScript(GetPlayer()->GetTarget(), SPAWN_SCRIPT_TARGETED, GetPlayer());
  1821. //player->SetTarget((int16*)app->pBuffer);
  1822. break;
  1823. }
  1824. case OP_ExamineInfoRequestMsg: {
  1825. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExamineInfoRequestMsg", opcode, opcode);
  1826. HandleExamineInfoRequest(app);
  1827. break;
  1828. }
  1829. case OP_QuickbarUpdateMsg:
  1830. //case OP_QuickbarAddMsg:
  1831. {
  1832. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuickbarUpdateMsg, OP_QuickbarAddMsg", opcode, opcode);
  1833. HandleQuickbarUpdateRequest(app);
  1834. break;
  1835. }
  1836. case OP_PredictionUpdateMsg: {
  1837. LogWrite(OPCODE__DEBUG, 7, "Opcode", "Opcode 0x%X (%i): OP_PredictionUpdateMsg from %s", opcode, opcode, GetPlayer()->GetName());
  1838. if (version <= 561) {
  1839. int8 offset = 9;
  1840. if (app->pBuffer[0] == 0xFF)
  1841. offset += 2;
  1842. if (app->size > offset) {
  1843. if (player->IsCasting()) {
  1844. float distance = 0;
  1845. float x = player->GetX();
  1846. float y = player->GetY();
  1847. float z = player->GetZ();
  1848. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1849. distance = player->GetDistance(x, y, z, false);
  1850. if (distance > .5)
  1851. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1852. }
  1853. else
  1854. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1855. player_pos_changed = true;
  1856. GetPlayer()->changed = true;
  1857. GetPlayer()->info_changed = true;
  1858. GetPlayer()->vis_changed = true;
  1859. GetPlayer()->AddChangedZoneSpawn();
  1860. //DumpPacket(app);
  1861. }
  1862. }
  1863. else {
  1864. EQ2Packet* app = new EQ2Packet(OP_PredictionUpdateMsg, 0, 0);
  1865. QueuePacket(app);
  1866. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1867. }
  1868. break;
  1869. }
  1870. case OP_RemoteCmdMsg: {
  1871. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RemoteCmdMsg", opcode, opcode);
  1872. if (app->size > 0) {
  1873. EQ2_CommandString remote(app->pBuffer, app->size);
  1874. LogWrite(PACKET__DEBUG, 1, "Packet", "RemoteCmdMsg Packet dump:");
  1875. #if EQDEBUG >= 9
  1876. DumpPacket(app);
  1877. #endif
  1878. commands.Process(remote.handler, &remote.command, this);
  1879. }
  1880. else //bad client, disconnect
  1881. Disconnect();
  1882. break;
  1883. }
  1884. case OP_CancelSpellCast: {
  1885. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CancelSpellCast", opcode, opcode);
  1886. current_zone->Interrupted(player, 0, 0, true);
  1887. SimpleMessage(CHANNEL_SPELLS_OTHER, "You stop casting.");
  1888. break;
  1889. }
  1890. case OP_UpdatePositionMsg: {
  1891. LogWrite(OPCODE__DEBUG, 7, "Opcode", "Opcode 0x%X (%i): OP_UpdatePositionMsg from %s", opcode, opcode, GetPlayer()->GetName());
  1892. int8 offset = 13;
  1893. if (app->pBuffer[0] == 0xFF)
  1894. offset += 2;
  1895. if (app->size > offset) {
  1896. if (player->IsCasting()) {
  1897. float distance = 0;
  1898. float x = player->GetX();
  1899. float y = player->GetY();
  1900. float z = player->GetZ();
  1901. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1902. distance = player->GetDistance(x, y, z, false);
  1903. if (distance > .5)
  1904. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1905. }
  1906. else
  1907. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1908. player_pos_changed = true;
  1909. GetPlayer()->changed = true;
  1910. GetPlayer()->info_changed = true;
  1911. GetPlayer()->vis_changed = true;
  1912. GetPlayer()->AddChangedZoneSpawn();
  1913. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1914. //DumpPacket(app);
  1915. }
  1916. break;
  1917. }
  1918. case OP_MailSendMessageMsg: {
  1919. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MailSendMessageMsg", opcode, opcode);
  1920. HandleSentMail(app);
  1921. break;
  1922. }
  1923. case OP_StopTrackingMsg: {
  1924. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopTrackingMsg", opcode, opcode);
  1925. player->GetZone()->RemovePlayerTracking(player, TRACKING_STOP);
  1926. break;
  1927. }
  1928. case OP_BeginTrackingMsg: {
  1929. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginTrackingMsg", opcode, opcode);
  1930. PacketStruct* packet = configReader.getStruct("WS_BeginTracking", GetVersion());
  1931. if (packet) {
  1932. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1933. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1934. Spawn* spawn = player->GetSpawnWithPlayerID(spawn_id);
  1935. if (spawn) {
  1936. AddWaypoint(spawn->GetName(), WAYPOINT_CATEGORY_TRACKING, spawn_id);
  1937. BeginWaypoint(spawn->GetName(), spawn->GetX(), spawn->GetY(), spawn->GetZ());
  1938. player->GetZone()->RemovePlayerTracking(player, TRACKING_CLOSE_WINDOW);
  1939. }
  1940. }
  1941. safe_delete(packet);
  1942. }
  1943. break;
  1944. }
  1945. case OP_BioUpdateMsg: {
  1946. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BioUpdateMsg", opcode, opcode);
  1947. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  1948. if (packet) {
  1949. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1950. player->SetBiography(packet->getType_EQ2_16BitString_ByName("biography").data);
  1951. }
  1952. safe_delete(packet);
  1953. }
  1954. break;
  1955. }
  1956. case OP_RewardPackMsg: {
  1957. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RewardPackMsg", opcode, opcode);
  1958. /* 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
  1959. when we come across it (scatman) */
  1960. const char* name = app->GetOpcodeName();
  1961. if (name)
  1962. LogWrite(WORLD__DEBUG, 0, "World", "%s Received OP_RewardPackMsg %04i", name, app->GetRawOpcode());
  1963. else
  1964. LogWrite(WORLD__DEBUG, 0, "World", "Received OP_RewardPackMsg %04i", app->GetRawOpcode());
  1965. //DumpPacket(app);
  1966. PacketStruct* packet = configReader.getStruct("WS_RewardPackMsg", GetVersion());
  1967. if (packet) {
  1968. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1969. string recruiter_name = packet->getType_EQ2_16BitString_ByName("recruiter_name").data;
  1970. /* Player has contacted a guild recruiter */
  1971. if (recruiter_name.length() > 0) {
  1972. Guild* guild = guild_list.GetGuild(packet->getType_int32_ByName("guild_id"));
  1973. Client* recruiter = zone_list.GetClientByCharName(recruiter_name);
  1974. if (recruiter && guild) {
  1975. Message(CHANNEL_GUILD_EVENT, "Contact request sent to %s of %s.", recruiter->GetPlayer()->GetName(), guild->GetName());
  1976. 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()));
  1977. recruiter->PlaySound("ui_guild_page");
  1978. }
  1979. }
  1980. /* New picture taken for guild recruiting */
  1981. else {
  1982. //DumpPacket(app->pBuffer, app->size);
  1983. int32 guild_id = 0;
  1984. int16 picture_data_size = 0;
  1985. unsigned char* recruiter_picture_data = 0;
  1986. memcpy(&guild_id, app->pBuffer + 4, sizeof(int32));
  1987. memcpy(&picture_data_size, app->pBuffer + 15, sizeof(int16));
  1988. Guild* guild = guild_list.GetGuild(guild_id);
  1989. if (guild) {
  1990. GuildMember* gm = guild->GetGuildMember(player);
  1991. if (gm) {
  1992. safe_delete_array(gm->recruiter_picture_data);
  1993. recruiter_picture_data = new unsigned char[picture_data_size];
  1994. for (int16 i = 0; i < picture_data_size; i++)
  1995. memcpy(recruiter_picture_data + i, app->pBuffer + 17 + i, 2);
  1996. gm->recruiter_picture_data = recruiter_picture_data;
  1997. gm->recruiter_picture_data_size = picture_data_size;
  1998. guild->SetMemberSaveNeeded(true);
  1999. }
  2000. }
  2001. }
  2002. }
  2003. safe_delete(packet);
  2004. }
  2005. break;
  2006. }
  2007. case OP_PetOptions: {
  2008. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PetOptions", opcode, opcode);
  2009. Spawn* target = player->GetTarget();
  2010. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  2011. if (packet && target && (target == player->GetPet() || target == player->GetCharmedPet() || target == player->GetDeityPet() || target == player->GetCosmeticPet())) {
  2012. bool change = false;
  2013. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  2014. string name = packet->getType_EQ2_16BitString_ByName("pet_name").data;
  2015. if (strlen(name.c_str()) != 0 && SetPetName(name.c_str())) {
  2016. target->SetName(name.c_str());
  2017. GetCurrentZone()->SendUpdateTitles(target);
  2018. change = true;
  2019. }
  2020. int8 pet_behavior = player->GetInfoStruct()->get_pet_behavior();
  2021. // Check protect self setting and update if needed
  2022. if (packet->getType_int8_ByName("protect_self") == 1) {
  2023. if ((pet_behavior & 2) == 0) {
  2024. player->GetInfoStruct()->set_pet_behavior(pet_behavior + 2);
  2025. change = true;
  2026. }
  2027. }
  2028. else {
  2029. if ((pet_behavior & 2) != 0) {
  2030. player->GetInfoStruct()->set_pet_behavior(pet_behavior - 2);
  2031. change = true;
  2032. }
  2033. }
  2034. // Check protect master setting and update if needed
  2035. if (packet->getType_int8_ByName("protect_master") == 1) {
  2036. if ((pet_behavior & 1) == 0) {
  2037. player->GetInfoStruct()->set_pet_behavior(pet_behavior + 1);
  2038. change = true;
  2039. }
  2040. }
  2041. else {
  2042. if ((pet_behavior & 1) != 0) {
  2043. player->GetInfoStruct()->set_pet_behavior(pet_behavior - 1);
  2044. change = true;
  2045. }
  2046. }
  2047. int8 pet_movement = player->GetInfoStruct()->get_pet_movement();
  2048. // Check stay/follow setting and update if needed
  2049. if (packet->getType_int8_ByName("stay_follow_toggle") == 1) {
  2050. if (pet_movement != 2) {
  2051. player->GetInfoStruct()->set_pet_movement(2);
  2052. change = true;
  2053. }
  2054. }
  2055. else {
  2056. if (pet_movement != 1) {
  2057. player->GetInfoStruct()->set_pet_movement(1);
  2058. change = true;
  2059. }
  2060. }
  2061. // Ranged/Melee settings are not implemented yet
  2062. if (change)
  2063. player->SetCharSheetChanged(true);
  2064. }
  2065. safe_delete(packet);
  2066. }
  2067. break;
  2068. }
  2069. case OP_RecipeBook: {
  2070. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RecipeBook", opcode, opcode);
  2071. SendRecipeList();
  2072. break;
  2073. }
  2074. case OP_BuyPlayerHouseMsg: {
  2075. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BuyPlayerHouseMsg", opcode, opcode);
  2076. //DumpPacket(app);
  2077. int64 bank_money = GetPlayer()->GetBankCoinsPlat();
  2078. PacketStruct* packet = configReader.getStruct("WS_BuyHouse", GetVersion());
  2079. if (packet) {
  2080. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  2081. int64 house_id = 0;
  2082. if(GetVersion() <= 561) {
  2083. house_id = packet->getType_int32_ByName("house_id");
  2084. }
  2085. else {
  2086. house_id = packet->getType_int64_ByName("house_id");
  2087. }
  2088. HouseZone* hz = world.GetHouseZone(house_id);
  2089. if (hz) {
  2090. bool got_bank_money = BankHasCoin(hz->cost_coin);
  2091. int8 disable_alignment_req = rule_manager.GetGlobalRule(R_Player, DisableHouseAlignmentRequirement)->GetInt8();
  2092. std::vector<PlayerHouse*> houses = world.GetAllPlayerHouses(GetCharacterID());
  2093. if (houses.size() > 24)
  2094. {
  2095. SimpleMessage(CHANNEL_COLOR_YELLOW, "You already own 25 houses and may not own another.");
  2096. safe_delete(packet);
  2097. break;
  2098. }
  2099. if(disable_alignment_req && hz->alignment > 0 && hz->alignment != GetPlayer()->GetAlignment())
  2100. {
  2101. std::string req = "You must be of ";
  2102. if (hz->alignment == 1)
  2103. req.append("Good");
  2104. else
  2105. req.append("Evil");
  2106. req.append(" alignment to purchase this house");
  2107. SimpleMessage(CHANNEL_COLOR_YELLOW, req.c_str());
  2108. safe_delete(packet);
  2109. break;
  2110. }
  2111. int32 status_req = hz->cost_status;
  2112. int32 available_status = player->GetInfoStruct()->get_status_points();
  2113. if (status_req <= available_status && (!hz->cost_coin || (hz->cost_coin && player->RemoveCoins(hz->cost_coin))))
  2114. {
  2115. player->GetInfoStruct()->subtract_status_points(status_req);
  2116. ZoneServer* instance_zone = zone_list.GetByInstanceID(0, hz->zone_id, false, false);
  2117. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800; // 604800 = 7 days
  2118. int64 unique_id = database.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, instance_zone->GetInstanceID(), upkeep_due);
  2119. world.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, unique_id, instance_zone->GetInstanceID(), upkeep_due, 0, 0, GetPlayer()->GetName());
  2120. //ClientPacketFunctions::SendHousingList(this);
  2121. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(unique_id);
  2122. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 561 ? house_id : this->GetPlayer()->GetID());
  2123. PlaySound("coin_cha_ching");
  2124. }
  2125. else if (status_req <= available_status && got_bank_money == 1) {
  2126. player->GetInfoStruct()->subtract_status_points(status_req);
  2127. bool bankwithdrawl = BankWithdrawalNoBanker(hz->cost_coin);
  2128. //this should NEVER happen since we check with got_bank_money, however adding it here should something go nutty.
  2129. if (bankwithdrawl == 0) {
  2130. PlaySound("buy_failed");
  2131. SimpleMessage(CHANNEL_COLOR_RED, "There was an error in bankwithdrawl function.");
  2132. safe_delete(packet);
  2133. break;
  2134. }
  2135. ZoneServer* instance_zone = zone_list.GetByInstanceID(0, hz->zone_id, false, false);
  2136. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800; // 604800 = 7 days
  2137. int64 unique_id = database.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, instance_zone->GetInstanceID(), upkeep_due);
  2138. world.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, unique_id, instance_zone->GetInstanceID(), upkeep_due, 0, 0, GetPlayer()->GetName());
  2139. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(unique_id);
  2140. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 561 ? house_id : this->GetPlayer()->GetID());
  2141. PlaySound("coin_cha_ching");
  2142. }
  2143. else
  2144. {
  2145. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money to purchase the house.");
  2146. PlaySound("buy_failed");
  2147. }
  2148. }
  2149. }
  2150. }
  2151. safe_delete(packet);
  2152. break;
  2153. }
  2154. case OP_EnterHouseMsg: {
  2155. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EnterHouseMsg", opcode, opcode);
  2156. //DumpPacket(app);
  2157. PacketStruct* packet = configReader.getStruct("WS_EnterHouse", GetVersion());
  2158. if (packet) {
  2159. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  2160. PlayerHouse* ph = nullptr;
  2161. HouseZone* hz = nullptr;
  2162. int64 house_id = 0;
  2163. int32 spawn_index = 0;
  2164. if(GetVersion() <= 561) {
  2165. spawn_index = packet->getType_int32_ByName("house_id");
  2166. }
  2167. else {
  2168. house_id = packet->getType_int64_ByName("house_id");
  2169. }
  2170. ZoneServer* house = GetHouseZoneServer(spawn_index, house_id);
  2171. if (house) {
  2172. Zone(house, true);
  2173. }
  2174. }
  2175. }
  2176. safe_delete(packet);
  2177. break;
  2178. }
  2179. case OP_PayHouseUpkeepMsg: {
  2180. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PayHouseUpkeepMsg", opcode, opcode);
  2181. PacketStruct* packet = configReader.getStruct("WS_PayUpkeep", GetVersion());
  2182. if (packet) {
  2183. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  2184. int64 house_id = 0;
  2185. if(GetVersion() <= 561) {
  2186. house_id = packet->getType_int32_ByName("house_id");
  2187. }
  2188. else {
  2189. house_id = packet->getType_int64_ByName("house_id");
  2190. }
  2191. HouseZone* hz = nullptr;
  2192. PlayerHouse* ph = world.GetPlayerHouse(this, GetVersion() <= 561 ? house_id : 0, GetVersion() > 561 ? house_id : 0, &hz);
  2193. if (ph)
  2194. {
  2195. if (!hz)
  2196. {
  2197. Message(CHANNEL_COLOR_YELLOW, "HouseZone ID %u does NOT exist!", ph->house_id);
  2198. safe_delete(packet);
  2199. break;
  2200. }
  2201. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800;
  2202. if (((sint64)ph->upkeep_due - (sint64)Timer::GetUnixTimeStamp()) > 0)
  2203. {
  2204. upkeep_due = ph->upkeep_due + 604800; // 604800 = 7 days
  2205. if (upkeep_due > (Timer::GetUnixTimeStamp() + 7257600)) // 84 days max upkeep to pay https://eq2.zam.com/wiki/Housing_%28EQ2%29#Upkeep
  2206. {
  2207. Message(CHANNEL_COLOR_YELLOW, "You cannot pay more than 3 months of upkeep.");
  2208. PlaySound("buy_failed");
  2209. safe_delete(packet);
  2210. break;
  2211. }
  2212. }
  2213. bool escrowChange = false;
  2214. int64 statusReq = hz->upkeep_status;
  2215. int64 tmpRecoverStatus = 0;
  2216. if(ph->escrow_status && statusReq >= ph->escrow_status )
  2217. {
  2218. escrowChange = true;
  2219. tmpRecoverStatus = ph->escrow_status;
  2220. statusReq -= ph->escrow_status;
  2221. ph->escrow_status = 0;
  2222. }
  2223. else if (ph->escrow_status && statusReq && statusReq <= ph->escrow_status)
  2224. {
  2225. escrowChange = true;
  2226. ph->escrow_status -= statusReq;
  2227. tmpRecoverStatus = statusReq;
  2228. statusReq = 0;
  2229. }
  2230. int64 coinReq = hz->upkeep_coin;
  2231. int64 tmpRecoverCoins = 0;
  2232. if (ph->escrow_coins && coinReq >= ph->escrow_coins) // more required to upkeep than in escrow, subtract what we have left
  2233. {
  2234. escrowChange = true;
  2235. tmpRecoverCoins = ph->escrow_coins;
  2236. coinReq -= ph->escrow_coins;
  2237. ph->escrow_coins = 0;
  2238. }
  2239. else if (ph->escrow_coins && coinReq && coinReq <= ph->escrow_coins)
  2240. {
  2241. escrowChange = true;
  2242. // more than enough in escrow, subtract and make our cost 0!
  2243. ph->escrow_coins -= coinReq;
  2244. tmpRecoverCoins = coinReq;
  2245. coinReq = 0;
  2246. }
  2247. int32 available_status_points = player->GetInfoStruct()->get_status_points();
  2248. if(!statusReq || (statusReq && statusReq <= available_status_points))
  2249. {
  2250. if(coinReq && player->RemoveCoins(coinReq))
  2251. coinReq = 0;
  2252. if(!coinReq && statusReq && player->GetInfoStruct()->subtract_status_points(statusReq))
  2253. statusReq = 0;
  2254. }
  2255. bool got_bank_money = BankHasCoin(hz->upkeep_coin);
  2256. if (!coinReq && !statusReq) // TODO: Need option to take from bank if player does not have enough coin on them
  2257. {
  2258. database.AddHistory(ph, GetPlayer()->GetName(), "Paid Upkeep", Timer::GetUnixTimeStamp(), hz->upkeep_coin, 0, 0);
  2259. if (escrowChange)
  2260. database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins, ph->escrow_status);
  2261. ph->upkeep_due = upkeep_due;
  2262. database.SetHouseUpkeepDue(GetCharacterID(), ph->house_id, ph->instance_id, ph->upkeep_due);
  2263. //ClientPacketFunctions::SendHousingList(this);
  2264. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 561 ? house_id : this->GetPlayer()->GetID());
  2265. PlaySound("coin_cha_ching");
  2266. }
  2267. else if (!statusReq && got_bank_money == 1) {
  2268. bool bankwithdrawl = BankWithdrawalNoBanker(hz->upkeep_coin);
  2269. //this should NEVER happen since we check with got_bank_money, however adding it here should something go nutty.
  2270. if (bankwithdrawl == 0) {
  2271. PlaySound("buy_failed");
  2272. SimpleMessage(CHANNEL_COLOR_RED, "There was an error in bankwithdrawl function.");
  2273. safe_delete(packet);
  2274. break;
  2275. }
  2276. database.AddHistory(ph, GetPlayer()->GetName(), "Paid Upkeep", Timer::GetUnixTimeStamp(), hz->upkeep_coin, 0, 0);
  2277. if (escrowChange)
  2278. database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins, ph->escrow_status);
  2279. ph->upkeep_due = upkeep_due;
  2280. database.SetHouseUpkeepDue(GetCharacterID(), ph->house_id, ph->instance_id, ph->upkeep_due);
  2281. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 561 ? house_id : this->GetPlayer()->GetID());
  2282. PlaySound("coin_cha_ching");
  2283. }
  2284. else
  2285. {
  2286. // recover the escrow we were going to use but could not spend due to lack of funds
  2287. if (tmpRecoverCoins)
  2288. ph->escrow_coins += tmpRecoverCoins;
  2289. if(tmpRecoverStatus)
  2290. ph->escrow_status += tmpRecoverStatus;
  2291. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money or status to pay for upkeep.");
  2292. PlaySound("buy_failed");
  2293. }
  2294. }
  2295. else
  2296. Message(CHANNEL_COLOR_YELLOW, "PlayerHouse ID %u does NOT exist!", house_id);
  2297. }
  2298. }
  2299. safe_delete(packet);
  2300. break;
  2301. }
  2302. case OP_ExitHouseMsg: {
  2303. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExitHouseMsg", opcode, opcode);
  2304. int32 instance_id = GetCurrentZone()->GetInstanceID();
  2305. if (instance_id > 0) {
  2306. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(instance_id);
  2307. if (ph) {
  2308. HouseZone* hz = world.GetHouseZone(ph->house_id);
  2309. if (hz) {
  2310. ZoneServer* new_zone = zone_list.Get(hz->exit_zone_id);
  2311. // determine if this is an instanced zone that already exists
  2312. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(hz->exit_zone_id);
  2313. if (instance_zone || new_zone) {
  2314. GetPlayer()->SetX(hz->exit_x);
  2315. GetPlayer()->SetY(hz->exit_y);
  2316. GetPlayer()->SetZ(hz->exit_z);
  2317. GetPlayer()->SetHeading(hz->exit_heading);
  2318. if (instance_zone)
  2319. Zone(instance_zone->GetInstanceID(), false, true);
  2320. else
  2321. Zone(new_zone, false);
  2322. }
  2323. }
  2324. }
  2325. }
  2326. break;
  2327. }
  2328. case OP_QuestJournalWaypointMsg: {
  2329. //DumpPacket(app);
  2330. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalWaypointMsg", opcode, opcode);
  2331. PacketStruct* packet = configReader.getStruct("WS_QuestJournalWaypoint", GetVersion());
  2332. if (packet) {
  2333. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  2334. if(GetVersion() <= 561) {
  2335. int32 quest_id = packet->getType_int32_ByName("quest_id");
  2336. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  2337. if (player->player_quests.count(quest_id) > 0 && player->player_quests[quest_id]) {
  2338. if(player->player_quests[quest_id]->GetTracked())
  2339. player->player_quests[quest_id]->SetTracked(false);
  2340. else
  2341. player->player_quests[quest_id]->SetTracked(true);
  2342. player->player_quests[quest_id]->SetSaveNeeded(true);
  2343. }
  2344. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  2345. }
  2346. else {
  2347. int32 quests = packet->getType_int32_ByName("num_quests");
  2348. if (quests > 100) // just picking a number higher than max allowed
  2349. {
  2350. LogWrite(CCLIENT__ERROR, 0, "Client", "num_quests = %u - quantity too high, aborting load.", quests);
  2351. break;
  2352. }
  2353. LogWrite(CCLIENT__DEBUG, 0, "Client", "num_quests = %u", quests);
  2354. for (int32 i = 0; i < quests; i++) {
  2355. int32 id = packet->getType_int32_ByName("quest_id_0", i);
  2356. if (id == 0)
  2357. continue;
  2358. LogWrite(CCLIENT__DEBUG, 5, "Client", "quest_id = %u", id);
  2359. bool tracked = packet->getType_int8_ByName("quest_tracked_0", i) == 1 ? true : false;
  2360. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  2361. if (player->player_quests.count(id) > 0 && player->player_quests[id]) {
  2362. player->player_quests[id]->SetTracked(tracked);
  2363. player->player_quests[id]->SetSaveNeeded(true);
  2364. }
  2365. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  2366. }
  2367. }
  2368. }
  2369. safe_delete(packet);
  2370. }
  2371. break;
  2372. }
  2373. case OP_PaperdollImage: {
  2374. /* PacketStruct* packet = configReader.getStruct("WS_PaperdollImage", version);
  2375. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  2376. //First check if this is a new image... delete an existing partial image if one exists
  2377. int8 packet_index = packet->getType_int8_ByName("packetIndex");
  2378. if (packet_index == 0) {
  2379. safe_delete_array(incoming_paperdoll.image_bytes);
  2380. incoming_paperdoll.last_received_packet_index = 0;
  2381. incoming_paperdoll.current_size_bytes = 0;
  2382. }
  2383. //return if this packet is not the one we are expecting...
  2384. else if (packet_index != incoming_paperdoll.last_received_packet_index + 1) {
  2385. safe_delete(packet);
  2386. break;
  2387. }
  2388. //Check how many packets we're supposed to be receiving for this/these images
  2389. incoming_paperdoll.image_num_packets = packet->getType_int8_ByName("totalNumPackets");
  2390. //Check the image type, if this is a new type in the same series of packets we have a new image
  2391. int8 img_type = packet->getType_int8_ByName("image_type");
  2392. if (packet_index != 0 && img_type != incoming_paperdoll.image_type) {
  2393. //We have a new image. Save the old data and clear before continuing
  2394. SavePlayerImages();
  2395. }
  2396. incoming_paperdoll.image_type = img_type;
  2397. //Get the size of the image data in this packet
  2398. sint64 image_size = packet->getType_int32_ByName("imageSize");
  2399. if (image_size <= 0 || image_size > 1048576) {
  2400. //If this packet is saying that the array is size <= 0 or > 1 MiB return out... it shouldn't be those sizes ever
  2401. safe_delete(packet);
  2402. break;
  2403. }
  2404. //Create a new array
  2405. int32 new_image_size = image_size;
  2406. uchar* new_image = new uchar[incoming_paperdoll.current_size_bytes + new_image_size];
  2407. if (incoming_paperdoll.image_bytes) {
  2408. memcpy(new_image, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  2409. safe_delete_array(incoming_paperdoll.image_bytes);
  2410. }
  2411. //variable i should be the index in the packet of the first PNG file byte
  2412. vector<DataStruct*>* d_structs = packet->getStructs();
  2413. vector<DataStruct*>::iterator itr;
  2414. int32 i = 0;
  2415. for (itr = d_structs->begin(); itr != d_structs->end(); itr++) {
  2416. DataStruct* ds = (*itr);
  2417. if (strcmp(ds->GetName(), "pngData_0") != 0)
  2418. i += ds->GetDataSizeInBytes();
  2419. else
  2420. break;
  2421. }
  2422. //Return if this packet is bad and we would read out of bounds
  2423. if (app->size - i < new_image_size) {
  2424. safe_delete(packet);
  2425. safe_delete_array(new_image);
  2426. break;
  2427. }
  2428. uchar* tmp = new_image + incoming_paperdoll.current_size_bytes;
  2429. memcpy(tmp, app->pBuffer + i, new_image_size);
  2430. incoming_paperdoll.current_size_bytes += new_image_size;
  2431. incoming_paperdoll.image_bytes = new_image;
  2432. //Check if this is the last packet we're expecting for this image. Create a final image if so
  2433. if (incoming_paperdoll.image_num_packets == 1 ||
  2434. incoming_paperdoll.last_received_packet_index + 2 == incoming_paperdoll.image_num_packets) {
  2435. SavePlayerImages();
  2436. }
  2437. incoming_paperdoll.last_received_packet_index = packet_index;
  2438. }
  2439. safe_delete(packet);
  2440. */
  2441. break;
  2442. }
  2443. case OP_ReadyForTakeOffMsg:
  2444. {
  2445. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyForTakeOffMsg", opcode, opcode);
  2446. int32 index = GetCurrentZone()->GetFlightPathIndex(GetPendingFlightPath());
  2447. if (GetPendingFlightPath() > 0) {
  2448. if (index != -1) {
  2449. PacketStruct* packet = configReader.getStruct("WS_ClearForTakeOff", GetVersion());
  2450. if (packet) {
  2451. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  2452. packet->setDataByName("path_id", index);
  2453. packet->setDataByName("speed", GetCurrentZone()->GetFlightPathSpeed(GetPendingFlightPath()));
  2454. QueuePacket(packet->serialize());
  2455. safe_delete(packet);
  2456. on_auto_mount = true;
  2457. }
  2458. }
  2459. else {
  2460. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but unable to get an index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2461. Message(CHANNEL_ERROR, "Unable to get index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2462. EndAutoMount();
  2463. }
  2464. SetPendingFlightPath(0);
  2465. }
  2466. else
  2467. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but there is no pending flight path...");
  2468. break;
  2469. }
  2470. case OP_EarlyLandingRequestMsg:
  2471. {
  2472. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EarlyLandingRequestMsg", opcode, opcode);
  2473. EndAutoMount();
  2474. break;
  2475. }
  2476. case OP_SubmitCharCust:
  2477. {
  2478. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SubmitCharCust", opcode, opcode);
  2479. PacketStruct* packet = configReader.getStruct("WS_SubmitCharCust", version);
  2480. if (packet && packet->LoadPacketData(app->pBuffer, app->size, GetVersion() <= 561 ? false : true)) {
  2481. int8 type = packet->getType_int8_ByName("type");
  2482. if (type == 0) {
  2483. /*if (player->custNPC) {
  2484. player->custNPCTarget->CustomizeAppearance(packet);
  2485. current_zone->SendSpawnChanges(player->custNPCTarget);
  2486. }
  2487. else {*/
  2488. player->CustomizeAppearance(packet);
  2489. current_zone->SendSpawnChanges(player);
  2490. //}
  2491. }
  2492. }
  2493. safe_delete(packet);
  2494. /*
  2495. if (player->custNPC) {
  2496. memcpy(&player->appearance, &player->SavedApp, sizeof(AppearanceData));
  2497. memcpy(&player->features, &player->SavedFeatures, sizeof(CharFeatures));
  2498. if (player->custNPCTarget->IsBot())
  2499. database.SaveBotAppearance((Bot*)player->custNPCTarget);
  2500. player->custNPC = false;
  2501. player->custNPCTarget = 0;
  2502. player->changed = true;
  2503. player->info_changed = true;
  2504. current_zone->SendSpawnChanges(player, this);
  2505. }*/
  2506. break;
  2507. }
  2508. default: {
  2509. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): Unknown in %s", opcode, opcode, __FILE__);
  2510. const char* name = app->GetOpcodeName();
  2511. if (name)
  2512. LogWrite(OPCODE__DEBUG, 1, "Opcode", "%s Received %04X (%i)", name, app->GetRawOpcode(), app->GetRawOpcode());
  2513. else
  2514. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Received %04X (%i)", app->GetRawOpcode(), app->GetRawOpcode());
  2515. // keeping this around for debugging purposes
  2516. DumpPacket(app);
  2517. }
  2518. }
  2519. if (!eqs || !eqs->CheckActive()) {
  2520. return false;
  2521. }
  2522. return ret;
  2523. }
  2524. bool Client::HandleLootItem(Spawn* entity, Item* item, Spawn* target, bool overrideLootRestrictions) {
  2525. if (!item) {
  2526. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find item to loot!");
  2527. return false;
  2528. }
  2529. int32 conflictItemList = 0, conflictequipmentList = 0, conflictAppearanceEquipmentList = 0;
  2530. int16 lore_stack_count = 0;
  2531. Player* lootingPlayer = player;
  2532. Client* lootingClient = this;
  2533. if (target != nullptr && target != lootingPlayer && target->IsPlayer()) {
  2534. lootingPlayer = (Player*)target;
  2535. lootingClient = lootingPlayer->GetClient();
  2536. }
  2537. // needs to only be checked before expiration of loot restrictions
  2538. if (entity && !overrideLootRestrictions) {
  2539. if (entity->GetLootGroupID() > 0 && (!lootingPlayer->GetGroupMemberInfo() || lootingPlayer->GetGroupMemberInfo()->group_id != entity->GetLootGroupID())) {
  2540. 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());
  2541. return false;
  2542. }
  2543. if (entity->GetLootMethod() != GroupLootMethod::METHOD_FFA) {
  2544. switch (entity->GetLootMethod()) {
  2545. case GroupLootMethod::METHOD_LEADER: {
  2546. if (entity->GetLootGroupID() > 0 && (!lootingPlayer->GetGroupMemberInfo() || (lootingPlayer->GetGroupMemberInfo() && (lootingPlayer->GetGroupMemberInfo()->group_id != entity->GetLootGroupID() || !lootingPlayer->GetGroupMemberInfo()->leader)))) {
  2547. 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);
  2548. return false;
  2549. }
  2550. break;
  2551. }
  2552. case GroupLootMethod::METHOD_LOTTO:
  2553. case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
  2554. if (entity->IsLootTimerRunning()) {
  2555. 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);
  2556. return false;
  2557. }
  2558. break;
  2559. }
  2560. }
  2561. }
  2562. }
  2563. if (((conflictItemList = lootingPlayer->item_list.CheckSlotConflict(item, true, true, &lore_stack_count)) == LORE ||
  2564. (conflictequipmentList = lootingPlayer->equipment_list.CheckSlotConflict(item, true, &lore_stack_count)) == LORE ||
  2565. (conflictAppearanceEquipmentList = lootingPlayer->appearance_equipment_list.CheckSlotConflict(item, true, &lore_stack_count)) == LORE) && !item->CheckFlag(STACK_LORE)) {
  2566. Message(CHANNEL_COLOR_RED, "You cannot loot %s due to lore conflict.", item->name.c_str());
  2567. return false;
  2568. }
  2569. else if (conflictItemList == STACK_LORE || conflictequipmentList == STACK_LORE || conflictAppearanceEquipmentList == STACK_LORE) {
  2570. Message(CHANNEL_COLOR_RED, "You cannot loot %s due to stack lore conflict.", item->name.c_str());
  2571. return false;
  2572. }
  2573. if (lootingPlayer->item_list.HasFreeSlot() || lootingPlayer->item_list.CanStack(item)) {
  2574. if (lootingPlayer->item_list.AssignItemToFreeSlot(item)) {
  2575. if (item->CheckFlag2(HEIRLOOM)) { // TODO: RAID Support
  2576. GroupMemberInfo* gmi = lootingClient->GetPlayer()->GetGroupMemberInfo();
  2577. if (gmi && gmi->group_id)
  2578. {
  2579. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  2580. if (group)
  2581. {
  2582. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  2583. deque<GroupMemberInfo*>* members = group->GetMembers();
  2584. if (members) {
  2585. for (int8 i = 0; i < members->size(); i++) {
  2586. Entity* member = members->at(i)->member;
  2587. if (!member)
  2588. continue;
  2589. if ((member->GetZone() != lootingClient->GetPlayer()->GetZone()))
  2590. continue;
  2591. if (member->IsPlayer()) {
  2592. item->grouped_char_ids.insert(std::make_pair(((Player*)member)->GetCharacterID(), true));
  2593. item->save_needed = true;
  2594. }
  2595. }
  2596. }
  2597. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  2598. }
  2599. }
  2600. }
  2601. int8 type = CHANNEL_LOOT;
  2602. if (entity) {
  2603. lootingClient->Message(type, "You loot %s from the corpse of %s", item->CreateItemLink(GetVersion()).c_str(), entity->GetName());
  2604. }
  2605. else {
  2606. lootingClient->Message(type, "You found a %s.", item->CreateItemLink(GetVersion()).c_str());
  2607. }
  2608. Guild* guild = lootingPlayer->GetGuild();
  2609. if (guild && item->details.tier >= ITEM_TAG_LEGENDARY) {
  2610. char adjective[32];
  2611. int8 type;
  2612. memset(adjective, 0, sizeof(adjective));
  2613. if (item->details.tier >= ITEM_TAG_MYTHICAL) {
  2614. strncpy(adjective, "Mythical", sizeof(adjective) - 1);
  2615. type = GUILD_EVENT_LOOTS_MYTHICAL_ITEM;
  2616. }
  2617. else if (item->details.tier >= ITEM_TAG_FABLED) {
  2618. strncpy(adjective, "Fabled", sizeof(adjective) - 1);
  2619. type = GUILD_EVENT_LOOTS_FABELED_ITEM;
  2620. }
  2621. else {
  2622. strncpy(adjective, "Legendary", sizeof(adjective) - 1);
  2623. type = GUILD_EVENT_LOOTS_LEGENDARY_ITEM;
  2624. }
  2625. guild->AddNewGuildEvent(type, "%s has looted the %s %s", Timer::GetUnixTimeStamp(), true, lootingPlayer->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2626. guild->SendMessageToGuild(type, "%s has looted the %s %s", lootingPlayer->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2627. }
  2628. if (item->GetItemScript() && lua_interface)
  2629. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, lootingPlayer);
  2630. lootingClient->CheckPlayerQuestsItemUpdate(item);
  2631. if (GetVersion() <= 561) {
  2632. EQ2Packet* outapp = lootingPlayer->SendInventoryUpdate(GetVersion());
  2633. if (outapp)
  2634. lootingClient->QueuePacket(outapp);
  2635. }
  2636. return true;
  2637. }
  2638. else
  2639. lootingClient->SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  2640. }
  2641. else
  2642. lootingClient->SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to loot item: Inventory is FULL.");
  2643. return false;
  2644. }
  2645. bool Client::HandleLootItemByID(Spawn* entity, int32 item_id, Spawn* target) {
  2646. if (!entity) {
  2647. return false;
  2648. }
  2649. Item* item = entity->LootItem(item_id);
  2650. bool success = false;
  2651. success = HandleLootItem(entity, item, target);
  2652. if (!success)
  2653. entity->AddLootItem(item);
  2654. return success;
  2655. }
  2656. void Client::HandleLootItemRequestPacket(EQApplicationPacket* app) {
  2657. PacketStruct* packet = configReader.getStruct("WS_LootItem", GetVersion());
  2658. if (packet) {
  2659. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  2660. int32 loot_id = packet->getType_int32_ByName("loot_id");
  2661. bool loot_all = (packet->getType_int8_ByName("loot_all") == 1);
  2662. int32 target_id = packet->getType_int32_ByName("target_id");
  2663. int8 button_clicked = packet->getType_int8_ByName("button_clicked");
  2664. Spawn* spawn = GetCurrentZone()->GetSpawnByID(loot_id);
  2665. if(!spawn) {
  2666. safe_delete(packet);
  2667. return;
  2668. }
  2669. Item* item = nullptr;
  2670. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  2671. if (items) {
  2672. int32 items_looted = 0;
  2673. int32 item_id = packet->getType_int32_ByName("item_id_0");
  2674. for (int32 i = 0; i < items->size(); i++) {
  2675. Item* master_item = items->at(i);
  2676. if (master_item && (loot_all || master_item->details.item_id == item_id)) {
  2677. item = new Item(master_item);
  2678. if (item) {
  2679. loot_all = HandleLootItem(0, item);
  2680. if (loot_all) {
  2681. player->RemovePendingLootItem(loot_id, item->details.item_id);
  2682. if (GetVersion() <= 561) {
  2683. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2684. if (outapp)
  2685. QueuePacket(outapp);
  2686. }
  2687. if(master_item->details.item_id == item_id) {
  2688. break;
  2689. }
  2690. }
  2691. }
  2692. if (!loot_all)
  2693. break;
  2694. }
  2695. }
  2696. if(((loot_all && !item_id) || (loot_all && item_id && items->size() == 1)) || items->size() < 1) {
  2697. CloseLoot(loot_id);
  2698. }
  2699. else {
  2700. vector<Item*>* items2 = player->GetPendingLootItems(loot_id);
  2701. SendLootResponsePacket(spawn->GetLootCoins(), items2, spawn, true);
  2702. safe_delete(items2);
  2703. }
  2704. safe_delete(items);
  2705. safe_delete(packet);
  2706. return;
  2707. }
  2708. spawn->LockLoot();
  2709. bool unlockedLoot = false;
  2710. if (spawn && !spawn->Alive() && spawn->IsNPC() && ((NPC*)spawn)->Brain()->CheckLootAllowed(player)) {
  2711. if (loot_all) {
  2712. switch (spawn->GetLootMethod()) {
  2713. case GroupLootMethod::METHOD_LOTTO: {
  2714. spawn->AddLottoItemRequest(0xFFFFFFFF, GetPlayer()->GetID());
  2715. break;
  2716. }
  2717. case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
  2718. spawn->AddNeedGreedItemRequest(0xFFFFFFFF, GetPlayer()->GetID(), true);
  2719. }
  2720. default: {
  2721. if (!unlockedLoot) {
  2722. spawn->UnlockLoot();
  2723. unlockedLoot = true;
  2724. }
  2725. int32 item_id = 0;
  2726. while (loot_all && ((item_id = spawn->GetLootItemID()) > 0)) {
  2727. loot_all = HandleLootItemByID(spawn, item_id, GetPlayer());
  2728. }
  2729. break;
  2730. }
  2731. }
  2732. spawn->UnlockLoot();
  2733. if (spawn->GetLootMethod() == GroupLootMethod::METHOD_LOTTO) {
  2734. CloseLoot(loot_id);
  2735. }
  2736. }
  2737. else {
  2738. int8 item_count = packet->getType_int8_ByName("item_count");
  2739. for (int8 cur = 0; cur < item_count; cur++) {
  2740. char item_field_name[64];
  2741. snprintf(item_field_name, 64, "item_id_%u", cur);
  2742. int32 item_id = packet->getType_int32_ByName(item_field_name);
  2743. Spawn* target = this->GetPlayer();
  2744. if (target_id != 0xFFFFFFFF && GetPlayer()->GetGroupMemberInfo()) {
  2745. Spawn* destTarget = GetPlayer()->GetSpawnWithPlayerID(target_id);
  2746. if (destTarget && (!destTarget->IsPlayer() || !world.GetGroupManager()->IsInGroup(GetPlayer()->GetGroupMemberInfo()->group_id, ((Player*)destTarget)))) {
  2747. SimpleMessage(CHANNEL_COMMAND_TEXT, "HACKS!!");
  2748. safe_delete(packet);
  2749. spawn->UnlockLoot();
  2750. return;
  2751. }
  2752. target = destTarget;
  2753. }
  2754. bool breakLoopAllLooted = false;
  2755. switch (spawn->GetLootMethod()) {
  2756. case GroupLootMethod::METHOD_LOTTO: {
  2757. spawn->AddLottoItemRequest(item_id, GetPlayer()->GetID());
  2758. break;
  2759. }
  2760. case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
  2761. if (button_clicked == 3) { // decline
  2762. break;
  2763. }
  2764. if (GetVersion() <= 561) {
  2765. button_clicked = 1; // selecting is need
  2766. }
  2767. spawn->AddNeedGreedItemRequest(item_id, GetPlayer()->GetID(), (button_clicked == 1));
  2768. break;
  2769. }
  2770. default: {
  2771. if (!unlockedLoot) {
  2772. spawn->UnlockLoot();
  2773. unlockedLoot = true;
  2774. }
  2775. if (!loot_all) {
  2776. HandleLootItemByID(spawn, item_id, target);
  2777. }
  2778. else {
  2779. while (loot_all && ((item_id = spawn->GetLootItemID()) > 0)) {
  2780. loot_all = HandleLootItemByID(spawn, item_id, target);
  2781. }
  2782. breakLoopAllLooted = true;
  2783. }
  2784. break;
  2785. }
  2786. }
  2787. if (breakLoopAllLooted) {
  2788. break;
  2789. }
  2790. }
  2791. if (!unlockedLoot) {
  2792. spawn->UnlockLoot();
  2793. }
  2794. if (spawn->GetLootMethod() == GroupLootMethod::METHOD_LOTTO ||
  2795. (spawn->GetLootMethod() == GroupLootMethod::METHOD_NEED_BEFORE_GREED && item_count >= spawn->GetLootCount())) {
  2796. CloseLoot(loot_id);
  2797. }
  2798. }
  2799. if (GetVersion() > 561) {
  2800. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2801. if (outapp)
  2802. QueuePacket(outapp);
  2803. }
  2804. if (spawn->GetLootMethod() != GroupLootMethod::METHOD_LOTTO && spawn->GetLootMethod() != GroupLootMethod::METHOD_NEED_BEFORE_GREED) {
  2805. LootSpawnRequest(spawn);
  2806. }
  2807. else {
  2808. spawn->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
  2809. }
  2810. if (!spawn->HasLoot()) {
  2811. CloseLoot(loot_id);
  2812. if (spawn->IsNPC())
  2813. GetCurrentZone()->RemoveDeadSpawn(spawn);
  2814. }
  2815. }
  2816. else {
  2817. spawn->UnlockLoot();
  2818. if (!spawn) {
  2819. LogWrite(WORLD__ERROR, 0, "World", "Unknown id of %u when looting!", loot_id);
  2820. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn to loot!");
  2821. }
  2822. else
  2823. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not unable to loot that at this time.");
  2824. }
  2825. }
  2826. safe_delete(packet);
  2827. }
  2828. }
  2829. void Client::HandleSkillInfoRequest(EQApplicationPacket* app) {
  2830. PacketStruct* request = 0;
  2831. // cout << "Request: \n";
  2832. // DumpPacket(app);
  2833. switch (app->pBuffer[0]) {
  2834. case 0: { //items
  2835. request = configReader.getStruct("WS_SkillInfoItemRequest", GetVersion());
  2836. if (request) {
  2837. if(request->LoadPacketData(app->pBuffer, app->size)) {
  2838. Item* item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(request->getType_int32_ByName("unique_id"));
  2839. if (!item)
  2840. item = GetPlayer()->item_list.GetItemFromUniqueID(request->getType_int32_ByName("unique_id"), true);
  2841. if (item) {
  2842. PacketStruct* response = configReader.getStruct("WS_SkillInfoItemResponse", GetVersion());
  2843. if (response) {
  2844. response->setDataByName("request_type", request->getType_int32_ByName("request_type"));
  2845. response->setDataByName("unique_id", request->getType_int32_ByName("unique_id"));
  2846. response->setSmallStringByName("name", item->name.c_str());
  2847. EQ2Packet* app2 = response->serialize();
  2848. //DumpPacket(app2);
  2849. QueuePacket(app2);
  2850. safe_delete(response);
  2851. }
  2852. }
  2853. }
  2854. safe_delete(request);
  2855. }
  2856. break;
  2857. }
  2858. case 2: {//spells
  2859. request = configReader.getStruct("WS_SkillInfoSpellRequest", GetVersion());
  2860. if (request) {
  2861. if(request->LoadPacketData(app->pBuffer, app->size)) {
  2862. int32 id = request->getType_int32_ByName("id");
  2863. int8 tier = request->getType_int32_ByName("unique_id"); //on live this is really unique_id, but I'm going to make it tier instead :)
  2864. Spell* spell = master_spell_list.GetSpell(id, tier);
  2865. PacketStruct* response = configReader.getStruct("WS_SkillInfoResponse", GetVersion());
  2866. if (response) {
  2867. response->setDataByName("request_type", 2);
  2868. response->setDataByName("unique_id", tier);
  2869. response->setDataByName("id", id);
  2870. if (spell)
  2871. response->setSmallStringByName("name", spell->GetName());
  2872. else
  2873. response->setSmallStringByName("name", "Unknown Spell");
  2874. EQ2Packet* app2 = response->serialize();
  2875. // DumpPacket(app2);
  2876. QueuePacket(app2);
  2877. safe_delete(response);
  2878. }
  2879. }
  2880. safe_delete(request);
  2881. }
  2882. break;
  2883. }
  2884. default: {
  2885. LogWrite(WORLD__ERROR, 0, "World", "Unknown SkillInfoRequest type of %i", (int)app->pBuffer[0]);
  2886. }
  2887. }
  2888. safe_delete(request);
  2889. }
  2890. void Client::HandleExamineInfoRequest(EQApplicationPacket* app) {
  2891. PacketStruct* request = 0;
  2892. if (!app || app->size == 0)
  2893. return;
  2894. //LogWrite(CCLIENT__DEBUG, 0, "Client", "Request2:");
  2895. int8 type = app->pBuffer[0];
  2896. DumpPacket(app->pBuffer,app->size);
  2897. //283: item: 0, effect: 1, recipe: 2, spell: 3
  2898. if (version <= 373) {
  2899. if (type == 1)
  2900. type = 4;
  2901. else if (type == 2)
  2902. type = 5;
  2903. }
  2904. if (type == 3) {
  2905. Spell* spell = 0;
  2906. bool trait_display;
  2907. request = configReader.getStruct((GetVersion() <= 373) ? "WS_ExamineInfoRequest" : "WS_ExamineInfoRequestMsg", GetVersion());
  2908. if (!request) {
  2909. return;
  2910. }
  2911. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  2912. safe_delete(request);
  2913. return;
  2914. }
  2915. int32 id = request->getType_int32_ByName("id");
  2916. int32 tier = request->getType_int32_ByName("tier");
  2917. int32 trait_tier = request->getType_int32_ByName("unknown_id");
  2918. bool display = true;
  2919. if (version <= 373 && request->getType_int8_ByName("display") == 1) // this is really requesting a partial packet
  2920. display = false;
  2921. else if (version <= 561)
  2922. display = request->getType_int8_ByName("display");
  2923. else if (version > 561)
  2924. display = false; // clients default is false otherwise it pops up a window when hovering over the knowledge book abilities
  2925. LogWrite(CCLIENT__DEBUG, 5, "Client", "Client::HandleExamineInfoRequest from %s: Type: (%i) Tier: (%u) Unknown ID: (%u) Item ID: (%u)",GetPlayer()->GetName(),type,tier,trait_tier,id);
  2926. if (trait_tier != 0xFFFFFFFF) {
  2927. spell = master_spell_list.GetSpell(id, trait_tier);
  2928. if (!spell) {
  2929. spell = master_spell_list.GetSpell(id, trait_tier + 1);
  2930. }
  2931. trait_display = true;
  2932. }
  2933. else {
  2934. spell = master_spell_list.GetSpell(id, tier);
  2935. trait_display = false;
  2936. }
  2937. // if we can't find it on the master spell list, see if it is a custom spell
  2938. if (!spell)
  2939. {
  2940. lua_interface->FindCustomSpellLock();
  2941. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2942. if (tmpSpell)
  2943. spell = tmpSpell->spell;
  2944. lua_interface->FindCustomSpellUnlock();
  2945. }
  2946. if(!spell) { // fix ui timeout for classic, isle of refuge, dof, kos clients
  2947. int8 playerTier = GetPlayer()->GetSpellTier(id);
  2948. spell = master_spell_list.GetSpell(id, playerTier);
  2949. LogWrite(CCLIENT__WARNING, 0, "Client", "Client::HandleExamineInfoRequest from %s: Failed to find tier 1 spell. Last resort try to get the spell from the player book, spell %u, tier %u", GetPlayer()->GetName(),id,playerTier);
  2950. }
  2951. if (spell && !CountSentSpell(spell->GetSpellID(), spell->GetSpellTier())) {
  2952. if (!spell->IsCopiedSpell())
  2953. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  2954. EQ2Packet* app = spell->SerializeSpell(this, display, trait_display);
  2955. //DumpPacket(app);
  2956. QueuePacket(app);
  2957. }
  2958. else if(spell && GetVersion() <=561 && CountSentSpell(spell->GetSpellID(), spell->GetSpellTier())) {
  2959. EQ2Packet* app = spell->SerializeSpell(this, display, trait_display, GetVersion() <= 561 ? true : false);
  2960. //DumpPacket(app);
  2961. QueuePacket(app);
  2962. }
  2963. else {
  2964. LogWrite(CCLIENT__ERROR, 0, "Client", "Client::HandleExamineInfoRequest from %s: Failed to successfully send Type: (%i) Tier: (%u) Unknown ID: (%u) Item ID: (%u)",GetPlayer()->GetName(),type,tier,trait_tier,id);
  2965. }
  2966. }
  2967. else if (type == 0) {
  2968. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2969. if (!request) {
  2970. return;
  2971. }
  2972. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  2973. safe_delete(request);
  2974. return;
  2975. }
  2976. int32 id = request->getType_int32_ByName("id");
  2977. Item* item = 0;
  2978. // translate from unique id to spawn id for houses
  2979. Spawn* spawn = this->GetCurrentZone()->GetSpawnFromUniqueItemID(id);
  2980. bool wasSpawn = false;
  2981. if (spawn)
  2982. {
  2983. item = master_item_list.GetItem(spawn->GetPickupItemID());
  2984. if (item)
  2985. {
  2986. wasSpawn = true;
  2987. item = new Item(item);
  2988. item->details.unique_id = spawn->GetPickupUniqueItemID();
  2989. }
  2990. }
  2991. if (!item)
  2992. item = GetPlayer()->item_list.GetItemFromUniqueID(id, true);
  2993. if (!item)
  2994. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(id);
  2995. if (!item)
  2996. item = GetPlayer()->GetAppearanceEquipmentList()->GetItemFromUniqueID(id);
  2997. if (!item)
  2998. item = master_item_list.GetItem(id);
  2999. if (item) {// && sent_item_details.count(id) == 0){
  3000. MItemDetails.writelock(__FUNCTION__, __LINE__);
  3001. sent_item_details[id] = true;
  3002. MItemDetails.releasewritelock(__FUNCTION__, __LINE__);
  3003. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  3004. QueuePacket(app);
  3005. if (wasSpawn)
  3006. delete item;
  3007. }
  3008. else {
  3009. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  3010. DumpPacket(app);
  3011. }
  3012. }
  3013. else if (type == 1) {
  3014. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  3015. if (!request) {
  3016. return;
  3017. }
  3018. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  3019. safe_delete(request);
  3020. return;
  3021. }
  3022. int32 id = request->getType_int32_ByName("id");
  3023. int32 unique_id = request->getType_int32_ByName("unique_id");
  3024. Item* item = GetPlayer()->item_list.GetItemFromUniqueID(unique_id, true);
  3025. if (!item)
  3026. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(unique_id);
  3027. if (!item)
  3028. item = GetPlayer()->GetAppearanceEquipmentList()->GetItemFromUniqueID(unique_id);
  3029. if (!item)
  3030. item = master_item_list.GetItem(id);
  3031. if (item) {
  3032. MItemDetails.writelock(__FUNCTION__, __LINE__);
  3033. sent_item_details[id] = true;
  3034. MItemDetails.releasewritelock(__FUNCTION__, __LINE__);
  3035. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  3036. QueuePacket(app);
  3037. }
  3038. else {
  3039. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  3040. DumpPacket(app);
  3041. }
  3042. }
  3043. else if (type == 2) {
  3044. request = configReader.getStruct("WS_ExamineInfoItemLinkRequest", GetVersion());
  3045. if (!request) {
  3046. return;
  3047. }
  3048. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  3049. safe_delete(request);
  3050. return;
  3051. }
  3052. int32 id = request->getType_int32_ByName("item_id");
  3053. LogWrite(CCLIENT__DEBUG, 5, "Client", "Client::HandleExamineInfoRequest from %s: Found Type: (%i) Item ID: (%u)",GetPlayer()->GetName(),type,id);
  3054. //int32 unknown_0 = request->getType_int32_ByName("unknown",0);
  3055. //int32 unknown_1 = request->getType_int32_ByName("unknown",1);
  3056. //int8 unknown2 = request->getType_int8_ByName("unknown2");
  3057. //int32 unique_id = request->getType_int32_ByName("unique_id");
  3058. //int16 unknown5 = request->getType_sint16_ByName("unknown5");
  3059. //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);
  3060. Item* item = master_item_list.GetItem(id);
  3061. if (item) {
  3062. //only display popup for non merchant links
  3063. EQ2Packet* app = item->serialize(GetVersion(), (request->getType_int8_ByName("show_popup") != 0), GetPlayer(), true, 0, 0, GetVersion() > 561 ? true : false);
  3064. QueuePacket(app);
  3065. }
  3066. else {
  3067. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  3068. DumpPacket(app);
  3069. }
  3070. }
  3071. else if (type == 4) { //spell effect
  3072. request = configReader.getStruct("WS_ExamineSpellEffectRequest", GetVersion());
  3073. if (!request) {
  3074. return;
  3075. }
  3076. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  3077. safe_delete(request);
  3078. return;
  3079. }
  3080. int32 id = request->getType_int32_ByName("id");
  3081. int16 display = request->getType_int8_ByName("partial_info");
  3082. SpellEffects* effect = player->GetSpellEffect(id);
  3083. //printf("Type: (%i) Unknown5: (%i) Item ID: (%u)\n",type,unknown5,id);
  3084. if (effect) {
  3085. LogWrite(CCLIENT__DEBUG, 5, "Client", "Client::HandleExamineInfoRequest from %s: Found Type: (%i) Item ID: (%u)",GetPlayer()->GetName(),type,id);
  3086. int8 tier = effect->tier;
  3087. Spell* spell = master_spell_list.GetSpell(id, tier);
  3088. // if we can't find it on the master spell list, see if it is a custom spell
  3089. if (!spell)
  3090. {
  3091. lua_interface->FindCustomSpellLock();
  3092. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  3093. EQ2Packet* pack = 0;
  3094. if (tmpSpell)
  3095. spell = tmpSpell->spell;
  3096. lua_interface->FindCustomSpellUnlock();
  3097. }
  3098. if (spell && (version <= 561 || !CountSentSpell(id, tier))) { // fix DoF and KoS clients UI Timeout
  3099. if (!spell->IsCopiedSpell())
  3100. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  3101. int8 type = 0;
  3102. if (version <= 373)
  3103. type = 1;
  3104. EQ2Packet* app = spell->SerializeSpecialSpell(this, false, type, 0x81);
  3105. //DumpPacket(app);
  3106. QueuePacket(app);
  3107. }
  3108. }
  3109. else {
  3110. LogWrite(CCLIENT__ERROR, 0, "Client", "Client::HandleExamineInfoRequest from %s: Cannot Find Type: (%i) Item ID: (%u)",GetPlayer()->GetName(),type,id);
  3111. }
  3112. }
  3113. else if (type == 5) { // recipe info
  3114. request = configReader.getStruct((GetVersion() <= 373) ? "WS_ExamineInfoRequest" : "WS_ExamineInfoRequestMsg", GetVersion());
  3115. if (!request)
  3116. return;
  3117. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  3118. safe_delete(request);
  3119. return;
  3120. }
  3121. int32 id = 0;
  3122. if(GetVersion() < 546) {
  3123. id = request->getType_int32_ByName("id");
  3124. }
  3125. else if(GetVersion() <= 561) {
  3126. id = request->getType_int32_ByName("unique_id");
  3127. }
  3128. else {
  3129. id = request->getType_int32_ByName("unknown_id");
  3130. }
  3131. Recipe* recipe = master_recipe_list.GetRecipe(id);
  3132. if (recipe) {
  3133. EQ2Packet* app = recipe->SerializeRecipe(this, recipe, false, GetItemPacketType(GetVersion()), 0x02);
  3134. //DumpPacket(app);
  3135. QueuePacket(app);
  3136. }
  3137. }
  3138. else if (type == 6) { // AA spell info
  3139. Spell* spell = 0;
  3140. //Spell* spell2 = 0;
  3141. //AltAdvanceData* data = 0;
  3142. request = configReader.getStruct((GetVersion() <= 373) ? "WS_ExamineInfoRequest" : "WS_ExamineInfoRequestMsg", GetVersion());
  3143. if (!request)
  3144. return;
  3145. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  3146. safe_delete(request);
  3147. return;
  3148. }
  3149. int32 id = request->getType_int32_ByName("id");
  3150. int32 tier = GetPlayer()->GetSpellTier(id);
  3151. LogWrite(WORLD__INFO, 0, "World", "Examine Info Request->Unique ID: %u Tier: %u ", id, tier);
  3152. //data = master_aa_list.GetAltAdvancement(id);
  3153. //LogWrite(WORLD__INFO, 0, "World", "SOE Spell CRC: %u", data->spell_crc);
  3154. //spell = master_spell_list.GetSpellByCRC(data->spell_crc);
  3155. spell = master_spell_list.GetSpell(id, tier);
  3156. if (!spell)
  3157. spell = master_spell_list.GetSpell(id, 1);
  3158. if (!spell)
  3159. {
  3160. lua_interface->FindCustomSpellLock();
  3161. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  3162. if (tmpSpell)
  3163. spell = tmpSpell->spell;
  3164. lua_interface->FindCustomSpellUnlock();
  3165. }
  3166. if (!spell)
  3167. {
  3168. LogWrite(CCLIENT__ERROR, 0, "Client", "WORLD", "Client::HandleExamineInfoRequest from %s: FAILED Examine Info Request-> Spell ID: %u, tier: %i", GetPlayer()->GetName(), id, tier);
  3169. return;
  3170. }
  3171. //if (spell && sent_spell_details.count(spell->GetSpellID()) == 0) {
  3172. if (!spell->IsCopiedSpell())
  3173. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  3174. // EQ2Packet* app = spell->SerializeAASpell(this,tier, data, false, GetItemPacketType(GetVersion()), 0x04);
  3175. LogWrite(WORLD__INFO, 0, "WORLD", "Examine Info Request-> Spell ID: %u", spell->GetSpellID());
  3176. if(GetVersion() > 561) {
  3177. EQ2Packet* app = master_spell_list.GetAASpellPacket(id, tier, this, false, 0x4F);//0x45 change version to match client
  3178. /////////////////////////////////////////GetAASpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type) {
  3179. //DumpPacket(app);
  3180. QueuePacket(app);
  3181. }
  3182. //}
  3183. }
  3184. else {
  3185. LogWrite(CCLIENT__ERROR, 0, "World", "Client::HandleExamineInfoRequest from %s: Unknown examine request: %i", GetPlayer()->GetName(), (int)type);
  3186. DumpPacket(app);
  3187. }
  3188. safe_delete(request);
  3189. }
  3190. void Client::HandleQuickbarUpdateRequest(EQApplicationPacket* app) {
  3191. PacketStruct* request = configReader.getStruct("WS_QuickBarUpdateRequest", GetVersion());
  3192. if (request) {
  3193. if(request->LoadPacketData(app->pBuffer, app->size)) {
  3194. int32 id = request->getType_int32_ByName("id");
  3195. int32 bar = request->getType_int32_ByName("hotbar_number");
  3196. int32 slot = request->getType_int32_ByName("hotkey_slot");
  3197. int32 type = request->getType_int32_ByName("type");
  3198. int8 tier = request->getType_int32_ByName("unique_id");
  3199. EQ2_16BitString text = request->getType_EQ2_16BitString_ByName("text");
  3200. Spell* spell = 0;
  3201. if (type == 0xFFFFFFFF)
  3202. GetPlayer()->RemoveQuickbarItem(bar, slot);
  3203. else {
  3204. if (type == QUICKBAR_NORMAL)
  3205. spell = master_spell_list.GetSpell(id, tier);
  3206. if (spell)
  3207. GetPlayer()->AddQuickbarItem(bar, slot, type, spell->GetSpellIcon(), spell->GetSpellIconBackdrop(), id, tier, 0, text.data.c_str());
  3208. else
  3209. GetPlayer()->AddQuickbarItem(bar, slot, type, 0, 0, id, 0, 0, text.data.c_str());
  3210. }
  3211. }
  3212. safe_delete(request);
  3213. }
  3214. }
  3215. bool Client::Process(bool zone_process) {
  3216. bool ret = true;
  3217. // EQS can become null if player is linkdead, we want to always be able to process the camp/linkdead timers when active
  3218. if ((camp_timer && camp_timer->Check()) || (linkdead_timer && linkdead_timer->Check())) {
  3219. ResetSendMail();
  3220. if(getConnection())
  3221. getConnection()->SendDisconnect(false);
  3222. safe_delete(camp_timer);
  3223. if(linkdead_timer) {
  3224. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player %s triggered linkdead timer, disconnecting", GetPlayer()->GetName());
  3225. // we remove the linkdead status and force a camp out immediately
  3226. if((GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_LINKDEAD) > 0) {
  3227. GetPlayer()->SetActivityStatus(GetPlayer()->GetActivityStatus() - ACTIVITY_STATUS_LINKDEAD);
  3228. }
  3229. if ((GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0) {
  3230. GetPlayer()->SetActivityStatus(GetPlayer()->GetActivityStatus() + ACTIVITY_STATUS_CAMPING);
  3231. }
  3232. }
  3233. safe_delete(linkdead_timer);
  3234. ret = false;
  3235. }
  3236. if (!eqs) {
  3237. return false;
  3238. }
  3239. if ((connected_to_zone && !zone_process) || (!connected_to_zone && zone_process)) {
  3240. return true;
  3241. }
  3242. switch(new_client_login) {
  3243. case NewLoginState::LOGIN_SEND: {
  3244. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendLoginInfo to new client...");
  3245. SendLoginInfo();
  3246. new_client_login = NewLoginState::LOGIN_NONE;
  3247. break;
  3248. }
  3249. case NewLoginState::LOGIN_INITIAL_LOAD: {
  3250. bool isDBActive = database.IsActiveQuery(GetCharacterID());
  3251. // wait for starting skills/spells to load and reload from DB.
  3252. if(!isDBActive) {
  3253. if (GetPlayer()->GetInfoStruct()->get_reload_player_spells()) {
  3254. database.LoadCharacterSpells(GetCharacterID(), GetPlayer());
  3255. GetPlayer()->GetInfoStruct()->set_reload_player_spells(0);
  3256. }
  3257. new_client_login = NewLoginState::LOGIN_SEND;
  3258. }
  3259. break;
  3260. }
  3261. case NewLoginState::LOGIN_ALLOWED: {
  3262. int32 count = 0;
  3263. if(!GetPlayer()->IsReturningFromLD())
  3264. {
  3265. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Skills for player '%s'...", player->GetName());
  3266. count = database.LoadCharacterSkills(GetCharacterID(), player);
  3267. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Spells for player '%s'...", player->GetName());
  3268. count = database.LoadCharacterSpells(GetCharacterID(), player);
  3269. }
  3270. else
  3271. {
  3272. LogWrite(CCLIENT__INFO, 0, "Client", "Player is returning from linkdead status (Player does not need reload) thus skipping database loading for '%s'...", player->GetName());
  3273. }
  3274. // get the latest character starting skills / spells, may have been updated after character creation
  3275. if(GetPlayer()->GetInfoStruct()->get_first_world_login()) {
  3276. world.SyncCharacterAbilities(this);
  3277. Query query;
  3278. query.AddQueryAsync(GetCharacterID(), &database, Q_UPDATE, "UPDATE characters set first_world_login = 0 where id=%u", GetCharacterID());
  3279. GetPlayer()->GetInfoStruct()->set_first_world_login(0);
  3280. }
  3281. new_client_login = NewLoginState::LOGIN_INITIAL_LOAD;
  3282. break;
  3283. }
  3284. case NewLoginState::LOGIN_DELAYED: {
  3285. if(!delay_msg_timer.Enabled() || delay_msg_timer.Check()) {
  3286. LogWrite(CCLIENT__INFO, 0, "Client", "Wait for zone %s to load for new client %s...", GetCurrentZone()->GetZoneName(), GetPlayer()->GetName());
  3287. delay_msg_timer.Start(1000, true);
  3288. }
  3289. if(!GetCurrentZone()->IsLoading()) {
  3290. new_client_login = NewLoginState::LOGIN_ALLOWED;
  3291. }
  3292. return true;
  3293. break;
  3294. }
  3295. }
  3296. delay_msg_timer.Disable();
  3297. sockaddr_in to;
  3298. memset((char*)&to, 0, sizeof(to));
  3299. to.sin_family = AF_INET;
  3300. to.sin_port = port;
  3301. to.sin_addr.s_addr = ip;
  3302. /************ Get all packets from packet manager out queue and process them ************/
  3303. EQApplicationPacket* app = 0;
  3304. if (eqs && !eqs->CheckActive()) {
  3305. num_active_failures++;
  3306. LogWrite(CCLIENT__DEBUG, 7, "Client", "%s, num_active_failures = %i", __FUNCTION__, num_active_failures);
  3307. if (num_active_failures > 100) {
  3308. return false;
  3309. }
  3310. return true;
  3311. }
  3312. while (ret && eqs && (app = eqs->PopPacket())) {
  3313. ret = HandlePacket(app);
  3314. LogWrite(CCLIENT__DEBUG, 5, "Client", "Func: %s, Line: %i, Opcode: '%s'", __FUNCTION__, __LINE__, app->GetOpcodeName());
  3315. delete app;
  3316. }
  3317. if (GetCurrentZone() && !GetCurrentZone()->IsLoading() && GetCurrentZone()->GetSpawnByID(GetPlayer()->GetID()) && should_load_spells) {
  3318. //database.LoadCharacterActiveSpells(player);
  3319. player->UnlockAllSpells(true);
  3320. should_load_spells = false;
  3321. }
  3322. if(spawn_removal_timer.Check() && GetPlayer()) {
  3323. GetPlayer()->ProcessSpawnRangeUpdates();
  3324. GetPlayer()->CheckSpawnStateQueue();
  3325. }
  3326. if (delayedLogin && delayTimer.Enabled() && delayTimer.Check())
  3327. {
  3328. if (!HandleNewLogin(delayedAccountID, delayedAccessKey))
  3329. return false;
  3330. }
  3331. if (quest_updates) {
  3332. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, ProcessQuestUpdates", __FUNCTION__, __LINE__);
  3333. ProcessQuestUpdates();
  3334. }
  3335. int32 queue_timer_delay = rule_manager.GetGlobalRule(R_Client, QuestQueueTimer)->GetInt32();
  3336. if(queue_timer_delay < 10) {
  3337. queue_timer_delay = 10;
  3338. }
  3339. if (last_update_time > 0 && last_update_time < (Timer::GetCurrentTime2() - queue_timer_delay)) {
  3340. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, CheckQuestQueue", __FUNCTION__, __LINE__);
  3341. CheckQuestQueue();
  3342. }
  3343. MSaveSpellStateMutex.lock();
  3344. if(save_spell_state_timer.Check())
  3345. {
  3346. save_spell_state_timer.Disable();
  3347. GetPlayer()->SaveSpellEffects();
  3348. }
  3349. MSaveSpellStateMutex.unlock();
  3350. if (temp_placement_timer.Check()) {
  3351. if(GetTempPlacementSpawn() && GetPlayer()->WasSentSpawn(GetTempPlacementSpawn()->GetID()) && !hasSentTempPlacementSpawn) {
  3352. SendMoveObjectMode(GetTempPlacementSpawn(), 0);
  3353. hasSentTempPlacementSpawn = true;
  3354. temp_placement_timer.Disable();
  3355. }
  3356. }
  3357. if (pos_update.Check())
  3358. {
  3359. ProcessStateCommands();
  3360. GetPlayer()->ResetMentorship(); // check if we need to asynchronously reset mentorship
  3361. if(GetPlayer()->GetRegionMap())
  3362. GetPlayer()->GetRegionMap()->TicRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  3363. if(!player_pos_changed && IsReadyForUpdates() && player_pos_timer < Timer::GetCurrentTime2() && enabled_player_pos_timer) {
  3364. if(version > 373) {
  3365. GetPlayer()->info_changed = true;
  3366. GetPlayer()->vis_changed = true;
  3367. GetPlayer()->position_changed = true;
  3368. GetPlayer()->changed = true;
  3369. GetPlayer()->AddChangedZoneSpawn();
  3370. }
  3371. player_pos_timer = Timer::GetCurrentTime2()+5000;
  3372. enabled_player_pos_timer = false;
  3373. }
  3374. if(player_pos_changed && IsReadyForUpdates()) {
  3375. player_pos_timer = Timer::GetCurrentTime2()+500;
  3376. enabled_player_pos_timer = true;
  3377. if(!underworld_cooldown_timer.Enabled() || (underworld_cooldown_timer.Enabled() && underworld_cooldown_timer.Check())) {
  3378. bool underworld = false;
  3379. if(rule_manager.GetGlobalRule(R_Zone, UseMapUnderworldCoords)->GetBool()) {
  3380. if(GetCurrentZone()->GetUnderWorld() != -1000000.0f) {
  3381. if(GetPlayer()->GetY() < GetCurrentZone()->GetUnderWorld())
  3382. underworld = true;
  3383. }
  3384. else if(GetPlayer()->GetMap() && GetPlayer()->GetMap()->GetMinY() != 9999999.0f && GetPlayer()->GetY() < (GetPlayer()->GetMap()->GetMinY() + rule_manager.GetGlobalRule(R_Zone, MapUnderworldCoordOffset)->GetFloat())) {
  3385. underworld = true;
  3386. }
  3387. }
  3388. else if(GetPlayer()->GetMap() && GetPlayer()->GetY() < GetCurrentZone()->GetUnderWorld()) {
  3389. underworld = true;
  3390. }
  3391. if(underworld) {
  3392. player->SetX(GetCurrentZone()->GetSafeX());
  3393. player->SetY(GetCurrentZone()->GetSafeY());
  3394. player->SetZ(GetCurrentZone()->GetSafeZ());
  3395. player->SetHeading(GetCurrentZone()->GetSafeHeading());
  3396. EQ2Packet* app = GetPlayer()->Move(player->GetX(), player->GetY(), player->GetZ(), GetVersion(), player->GetHeading());
  3397. if(app){
  3398. QueuePacket(app);
  3399. }
  3400. SimpleMessage(CHANNEL_COLOR_RED, "You have been teleported to a safe location in the zone, because you appeared to have fallen through the world.");
  3401. }
  3402. underworld_cooldown_timer.Start();
  3403. }
  3404. //GetPlayer()->CalculateLocation();
  3405. client_list.CheckPlayersInvisStatus(this);
  3406. player_pos_changed = false;
  3407. GetCurrentZone()->CheckTransporters(this);
  3408. if(GetPlayer()->GetRegionMap())
  3409. {
  3410. GetPlayer()->GetRegionMap()->MapRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  3411. }
  3412. }
  3413. else if (IsReadyForUpdates() && GetPlayer()->GetRegionMap()) {
  3414. GetPlayer()->GetRegionMap()->UpdateRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  3415. }
  3416. }
  3417. if (lua_interface && lua_debug && lua_debug_timer.Check())
  3418. lua_interface->UpdateDebugClients(this);
  3419. if (quest_pos_timer.Check())
  3420. CheckPlayerQuestsLocationUpdate();
  3421. if (player->GetSkills()->HasSkillUpdates()) {
  3422. vector<Skill*>* skills = player->GetSkills()->GetSkillUpdates();
  3423. if (skills) {
  3424. Skill* skill = 0;
  3425. vector<Skill*>::iterator itr;
  3426. for (itr = skills->begin(); itr != skills->end(); itr++) {
  3427. skill = *itr;
  3428. SkillChanged(skill, skill->previous_val, skill->current_val);
  3429. }
  3430. EQ2Packet* app = GetPlayer()->skill_list.GetSkillPacket(GetVersion());
  3431. if (app) QueuePacket(app);
  3432. safe_delete(skills);
  3433. }
  3434. }
  3435. m_resurrect.writelock(__FUNCTION__, __LINE__);
  3436. if (current_rez.should_delete || (current_rez.expire_timer && current_rez.expire_timer->Check(false))) {
  3437. safe_delete(current_rez.expire_timer);
  3438. current_rez.expire_timer = 0;
  3439. current_rez.active = false;
  3440. current_rez.caster = 0;
  3441. current_rez.crit = false;
  3442. current_rez.crit_mod = 0;
  3443. current_rez.expire_timer = 0;
  3444. current_rez.heal_name = "";
  3445. current_rez.hp_perc = 0;
  3446. current_rez.mp_perc = 0;
  3447. current_rez.no_calcs = false;
  3448. current_rez.range = 0;
  3449. current_rez.should_delete = false;
  3450. current_rez.spell_name = "";
  3451. current_rez.spell_visual = 0;
  3452. current_rez.subspell = 0;
  3453. }
  3454. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  3455. // Quest timers
  3456. Quest* failed_step = 0;
  3457. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  3458. if (quest_timers.size() > 0) {
  3459. vector<int32>::iterator itr;
  3460. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  3461. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  3462. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  3463. if (player_quests->count(*itr) > 0 && player_quests->at(*itr)->GetStepTimer() != 0) {
  3464. Quest* quest = player_quests->at(*itr);
  3465. if (Timer::GetUnixTimeStamp() >= quest->GetStepTimer()) {
  3466. failed_step = quest;
  3467. break;
  3468. }
  3469. }
  3470. else {
  3471. itr = quest_timers.erase(itr);
  3472. break;
  3473. }
  3474. }
  3475. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  3476. }
  3477. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  3478. if (failed_step)
  3479. failed_step->StepFailed(failed_step->GetTimerStep());
  3480. if (player->ControlFlagsChanged())
  3481. player->SendControlFlagUpdates(this);
  3482. if (!eqs || (eqs && !eqs->CheckActive()))
  3483. ret = false;
  3484. // redundant to client disconnect
  3485. // if(!ret)
  3486. // Save();
  3487. return ret;
  3488. }
  3489. ClientList::ClientList() {
  3490. MClients.SetName("ClientList::MClients");
  3491. }
  3492. ClientList::~ClientList() {
  3493. }
  3494. void ClientList::ReloadQuests() {
  3495. list<Client*>::iterator client_iter;
  3496. Client* client = 0;
  3497. MClients.readlock(__FUNCTION__, __LINE__);
  3498. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3499. client = *client_iter;
  3500. if (client)
  3501. client->ReloadQuests();
  3502. }
  3503. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3504. }
  3505. void ClientList::CheckPlayersInvisStatus(Client* owner) {
  3506. if (!owner->GetPlayer() || (!owner->GetPlayer()->IsInvis() && !owner->GetPlayer()->IsStealthed()))
  3507. return;
  3508. list<Client*>::iterator client_iter;
  3509. Client* client = 0;
  3510. MClients.readlock(__FUNCTION__, __LINE__);
  3511. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3512. client = *client_iter;
  3513. if (client == owner || client->GetPlayer() == NULL)
  3514. continue;
  3515. if (client->GetPlayer()->CheckChangeInvisHistory((Entity*)owner->GetPlayer()))
  3516. client->GetPlayer()->GetZone()->SendSpawnChanges(owner->GetPlayer(), client, true, true);
  3517. }
  3518. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3519. }
  3520. void ClientList::RemovePlayerFromInvisHistory(int32 spawnID) {
  3521. list<Client*>::iterator client_iter;
  3522. Client* client = 0;
  3523. MClients.readlock(__FUNCTION__, __LINE__);
  3524. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3525. client = *client_iter;
  3526. if (!client->GetPlayer())
  3527. continue;
  3528. client->GetPlayer()->RemoveTargetInvisHistory(spawnID);
  3529. }
  3530. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3531. }
  3532. int32 ClientList::Count() {
  3533. return client_list.size();
  3534. }
  3535. void ClientList::Add(Client* client) {
  3536. MClients.writelock(__FUNCTION__, __LINE__);
  3537. client_list.push_back(client);
  3538. MClients.releasewritelock(__FUNCTION__, __LINE__);
  3539. }
  3540. Client* ClientList::FindByAccountID(int32 account_id) {
  3541. list<Client*>::iterator client_iter;
  3542. Client* client = 0;
  3543. Client* ret = 0;
  3544. MClients.readlock(__FUNCTION__, __LINE__);
  3545. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3546. client = *client_iter;
  3547. if (client->GetAccountID() == account_id) {
  3548. ret = client;
  3549. break;
  3550. }
  3551. }
  3552. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3553. return ret;
  3554. }
  3555. Client* ClientList::FindByName(char* charName) {
  3556. list<Client*>::iterator client_iter;
  3557. Client* client = 0;
  3558. Client* ret = 0;
  3559. MClients.readlock(__FUNCTION__, __LINE__);
  3560. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3561. client = *client_iter;
  3562. if (!client || !client->GetPlayer())
  3563. continue;
  3564. if (!strncmp(client->GetPlayer()->GetName(), charName, strlen(charName))) {
  3565. ret = client;
  3566. break;
  3567. }
  3568. }
  3569. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3570. return ret;
  3571. }
  3572. Client* ClientList::Get(int32 ip, int16 port) {
  3573. list<Client*>::iterator client_iter;
  3574. Client* client = 0;
  3575. Client* ret = 0;
  3576. MClients.readlock(__FUNCTION__, __LINE__);
  3577. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3578. client = *client_iter;
  3579. if (client->GetIP() == ip && client->GetPort() == port) {
  3580. ret = client;
  3581. break;
  3582. }
  3583. }
  3584. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3585. return ret;
  3586. }
  3587. void ClientList::Process() {
  3588. list<Client*>::iterator client_iter;
  3589. list<Client*>::iterator erase_iter;
  3590. Client* client = 0;
  3591. MClients.readlock(__FUNCTION__, __LINE__);
  3592. erase_iter = client_list.end();
  3593. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3594. client = *client_iter;
  3595. // have a sanity check because the client list can sometimes obtain null client pointers
  3596. if (!client || client->remove_from_list || (!client->Process())) { // if we should be removing from list, don't process any further
  3597. erase_iter = client_iter;
  3598. break;
  3599. }
  3600. }
  3601. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3602. if (erase_iter != client_list.end()) {
  3603. client = *erase_iter;
  3604. MClients.writelock(__FUNCTION__, __LINE__);
  3605. client_list.erase(erase_iter);
  3606. MClients.releasewritelock(__FUNCTION__, __LINE__);
  3607. if (client && !client->remove_from_list) {
  3608. struct in_addr in;
  3609. in.s_addr = client->GetIP();
  3610. LogWrite(WORLD__INFO, 0, "World", "Removing client from ip: %s port: %i", inet_ntoa(in), client->GetPort());
  3611. safe_delete(client);
  3612. }
  3613. }
  3614. }
  3615. void ClientList::RemoveConnection(EQStream* eqs) {
  3616. Client* client;
  3617. if (eqs) {
  3618. list<Client*>::iterator client_iter;
  3619. MClients.readlock(__FUNCTION__, __LINE__);
  3620. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3621. client = *client_iter;
  3622. if (client->getConnection() == eqs)
  3623. client->Disconnect(true);
  3624. }
  3625. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3626. }
  3627. }
  3628. bool ClientList::ContainsStream(EQStream* eqs) {
  3629. if (!eqs) {
  3630. return false;
  3631. }
  3632. list<Client*>::iterator client_iter;
  3633. bool ret = false;
  3634. MClients.readlock(__FUNCTION__, __LINE__);
  3635. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3636. if ((*client_iter)->getConnection() && (*client_iter)->getConnection()->GetRemotePort() == eqs->GetRemotePort() && (*client_iter)->getConnection()->GetRemoteIP() == eqs->GetRemoteIP()) {
  3637. ret = true;
  3638. break;
  3639. }
  3640. }
  3641. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3642. return ret;
  3643. }
  3644. void ClientList::Remove(Client* client, bool remove_data) {
  3645. client->remove_from_list = true;
  3646. if (remove_data) {
  3647. safe_delete(client);
  3648. }
  3649. }
  3650. void Client::SetCurrentZone(ZoneServer* zone) {
  3651. current_zone = zone;
  3652. if(player) {
  3653. player->SetZone(zone, GetVersion());
  3654. }
  3655. }
  3656. void Client::SetCurrentZone(int32 id) {
  3657. if (current_zone) {
  3658. //current_zone->GetCombat()->RemoveHate(player);
  3659. current_zone->RemoveSpawn(player, false, true, true, true, true);
  3660. }
  3661. SetCurrentZone(zone_list.Get(id));
  3662. }
  3663. void Client::SetCurrentZoneByInstanceID(int32 id, int32 zoneid) {
  3664. if (current_zone) {
  3665. //current_zone->GetCombat()->RemoveHate(player);
  3666. current_zone->RemoveSpawn(player, false, true, true, true, true);
  3667. }
  3668. SetCurrentZone(zone_list.GetByInstanceID(id, zoneid));
  3669. }
  3670. ZoneServer* Client::GetCurrentZone() {
  3671. return current_zone;
  3672. }
  3673. int8 Client::GetMessageChannelColor(int8 channel_type) {
  3674. if (GetVersion() >= 973 && GetVersion() <= 1000) {
  3675. if (channel_type == CHANNEL_LOOT)
  3676. return CHANNEL_COLOR_NEW_LOOT;
  3677. }
  3678. else if (GetVersion() >= 973) {
  3679. if (channel_type == CHANNEL_LOOT)
  3680. return CHANNEL_COLOR_NEWEST_LOOT;
  3681. }
  3682. if (GetVersion() <= 283) {
  3683. if (channel_type <=12)
  3684. return channel_type;
  3685. switch (channel_type) {
  3686. case CHANNEL_GROUP_CHAT:
  3687. case CHANNEL_GROUP_SAY:
  3688. case CHANNEL_RAID_SAY:
  3689. case CHANNEL_GUILD_CHAT:
  3690. case CHANNEL_GUILD_SAY:
  3691. case CHANNEL_OFFICER_SAY:
  3692. case CHANNEL_GUILD_MOTD:
  3693. return channel_type - 1;
  3694. case CHANNEL_PRIVATE_CHAT:
  3695. case CHANNEL_NONPLAYER_TELL:
  3696. return channel_type - 5;
  3697. case CHANNEL_PRIVATE_TELL:
  3698. case CHANNEL_TELL_FROM_CS:
  3699. return channel_type - 6;
  3700. case CHANNEL_CHAT_CHANNEL_TEXT:
  3701. case CHANNEL_OUT_OF_CHARACTER:
  3702. case CHANNEL_AUCTION:
  3703. case CHANNEL_CUSTOM_CHANNEL:
  3704. case CHANNEL_CHARACTER_TEXT:
  3705. case CHANNEL_REWARD:
  3706. case CHANNEL_DEATH:
  3707. case CHANNEL_PET_CHAT:
  3708. case CHANNEL_SKILL:
  3709. return channel_type - 7;
  3710. case CHANNEL_SPELLS:
  3711. case CHANNEL_YOU_CAST:
  3712. case CHANNEL_YOU_FAIL:
  3713. return channel_type - 8;
  3714. case CHANNEL_FRIENDLY_CAST:
  3715. case CHANNEL_FRIENDLY_FAIL:
  3716. case CHANNEL_OTHER_CAST:
  3717. case CHANNEL_OTHER_FAIL:
  3718. case CHANNEL_HOSTILE_CAST:
  3719. case CHANNEL_HOSTILE_FAIL:
  3720. case CHANNEL_WORN_OFF:
  3721. case CHANNEL_SPELLS_OTHER:
  3722. return channel_type - 9;
  3723. case CHANNEL_COMBAT:
  3724. return channel_type - 15;
  3725. case CHANNEL_HEROIC_OPPORTUNITY:
  3726. case CHANNEL_NON_MELEE_DAMAGE:
  3727. case CHANNEL_DAMAGE_SHIELD:
  3728. return channel_type - 16;
  3729. case CHANNEL_MELEE_COMBAT:
  3730. case CHANNEL_WARNINGS:
  3731. case CHANNEL_YOU_HIT:
  3732. case CHANNEL_YOU_MISS:
  3733. case CHANNEL_ATTACKER_HITS:
  3734. case CHANNEL_ATTACKER_MISSES:
  3735. return channel_type - 18;
  3736. case CHANNEL_OTHER_HIT:
  3737. case CHANNEL_OTHER_MISSES:
  3738. case CHANNEL_CRITICAL_HIT:
  3739. return channel_type - 22;
  3740. case CHANNEL_OTHER:
  3741. case CHANNEL_MONEY_SPLIT:
  3742. case CHANNEL_LOOT:
  3743. return channel_type - 30;
  3744. case CHANNEL_COMMAND_TEXT:
  3745. case CHANNEL_BROADCAST:
  3746. case CHANNEL_WHO:
  3747. case CHANNEL_COMMANDS:
  3748. case CHANNEL_MERCHANT:
  3749. case CHANNEL_MERCHANT_BUY_SELL:
  3750. case CHANNEL_CONSIDER_MESSAGE:
  3751. case CHANNEL_CON_MINUS_2:
  3752. case CHANNEL_CON_MINUS_1:
  3753. case CHANNEL_CON_0:
  3754. case CHANNEL_CON_1:
  3755. case CHANNEL_CON_2:
  3756. return channel_type - 31;
  3757. default: {
  3758. return CHANNEL_DEFAULT;
  3759. }
  3760. }
  3761. }
  3762. else if (GetVersion() <= 373) {
  3763. if (channel_type <=18)
  3764. return channel_type;
  3765. switch (channel_type) {
  3766. case CHANNEL_PRIVATE_CHAT:
  3767. case CHANNEL_NONPLAYER_TELL:
  3768. return 22;
  3769. case CHANNEL_PRIVATE_TELL:
  3770. case CHANNEL_TELL_FROM_CS:
  3771. return 23;
  3772. case CHANNEL_CHAT_CHANNEL_TEXT:
  3773. case CHANNEL_OUT_OF_CHARACTER:
  3774. case CHANNEL_CUSTOM_CHANNEL:
  3775. case CHANNEL_CHARACTER_TEXT:
  3776. case CHANNEL_REWARD:
  3777. case CHANNEL_DEATH:
  3778. case CHANNEL_PET_CHAT:
  3779. case CHANNEL_SKILL:
  3780. return 26;
  3781. case CHANNEL_AUCTION:
  3782. return 27;
  3783. case CHANNEL_SPELLS:
  3784. case CHANNEL_YOU_CAST:
  3785. case CHANNEL_YOU_FAIL:
  3786. return channel_type - 8;
  3787. case CHANNEL_FRIENDLY_CAST:
  3788. case CHANNEL_FRIENDLY_FAIL:
  3789. case CHANNEL_OTHER_CAST:
  3790. case CHANNEL_OTHER_FAIL:
  3791. case CHANNEL_HOSTILE_CAST:
  3792. case CHANNEL_HOSTILE_FAIL:
  3793. case CHANNEL_WORN_OFF:
  3794. case CHANNEL_SPELLS_OTHER:
  3795. return channel_type - 9;
  3796. case CHANNEL_COMBAT:
  3797. return channel_type - 15;
  3798. case CHANNEL_HEROIC_OPPORTUNITY:
  3799. case CHANNEL_NON_MELEE_DAMAGE:
  3800. case CHANNEL_DAMAGE_SHIELD:
  3801. return channel_type - 16;
  3802. case CHANNEL_MELEE_COMBAT:
  3803. case CHANNEL_WARNINGS:
  3804. case CHANNEL_YOU_HIT:
  3805. case CHANNEL_YOU_MISS:
  3806. case CHANNEL_ATTACKER_HITS:
  3807. case CHANNEL_ATTACKER_MISSES:
  3808. return channel_type - 18;
  3809. case CHANNEL_OTHER_HIT:
  3810. case CHANNEL_OTHER_MISSES:
  3811. case CHANNEL_CRITICAL_HIT:
  3812. return channel_type - 22;
  3813. case CHANNEL_OTHER:
  3814. case CHANNEL_MONEY_SPLIT:
  3815. case CHANNEL_LOOT:
  3816. return channel_type - 30;
  3817. case CHANNEL_COMMAND_TEXT:
  3818. case CHANNEL_BROADCAST:
  3819. case CHANNEL_WHO:
  3820. case CHANNEL_COMMANDS:
  3821. case CHANNEL_MERCHANT:
  3822. case CHANNEL_MERCHANT_BUY_SELL:
  3823. case CHANNEL_CONSIDER_MESSAGE:
  3824. case CHANNEL_CON_MINUS_2:
  3825. case CHANNEL_CON_MINUS_1:
  3826. case CHANNEL_CON_0:
  3827. case CHANNEL_CON_1:
  3828. case CHANNEL_CON_2:
  3829. return 68;
  3830. default: {
  3831. return CHANNEL_DEFAULT;
  3832. }
  3833. }
  3834. }
  3835. else if (GetVersion() <= 561) {
  3836. if (channel_type < 20)
  3837. return channel_type;
  3838. switch (channel_type) {
  3839. case CHANNEL_GUILD_MOTD:
  3840. case CHANNEL_GUILD_MEMBER_ONLINE:
  3841. case CHANNEL_GUILD_EVENT:
  3842. return channel_type + 1;
  3843. case CHANNEL_PRIVATE_CHAT:
  3844. case CHANNEL_NONPLAYER_TELL:
  3845. return channel_type - 1;
  3846. case CHANNEL_PRIVATE_TELL:
  3847. case CHANNEL_TELL_FROM_CS:
  3848. case CHANNEL_ARENA:
  3849. case CHANNEL_CHAT_CHANNEL_TEXT:
  3850. case CHANNEL_OUT_OF_CHARACTER:
  3851. case CHANNEL_AUCTION:
  3852. case CHANNEL_CUSTOM_CHANNEL:
  3853. case CHANNEL_CHARACTER_TEXT:
  3854. case CHANNEL_REWARD:
  3855. case CHANNEL_DEATH:
  3856. case CHANNEL_PET_CHAT:
  3857. case CHANNEL_SKILL:
  3858. case CHANNEL_FACTION:
  3859. case CHANNEL_SPELLS:
  3860. case CHANNEL_YOU_CAST:
  3861. case CHANNEL_YOU_FAIL:
  3862. return channel_type - 2;
  3863. case CHANNEL_FRIENDLY_CAST:
  3864. case CHANNEL_FRIENDLY_FAIL:
  3865. case CHANNEL_OTHER_CAST:
  3866. case CHANNEL_OTHER_FAIL:
  3867. case CHANNEL_HOSTILE_CAST:
  3868. case CHANNEL_HOSTILE_FAIL:
  3869. case CHANNEL_WORN_OFF:
  3870. case CHANNEL_SPELLS_OTHER:
  3871. case CHANNEL_HEAL_SPELLS:
  3872. case CHANNEL_HEALS:
  3873. case CHANNEL_FRIENDLY_HEALS:
  3874. case CHANNEL_OTHER_HEALS:
  3875. case CHANNEL_HOSTILE_HEALS:
  3876. return channel_type - 3;
  3877. case CHANNEL_COMBAT:
  3878. case CHANNEL_GENERAL_COMBAT:
  3879. case CHANNEL_HEROIC_OPPORTUNITY:
  3880. case CHANNEL_NON_MELEE_DAMAGE:
  3881. case CHANNEL_DAMAGE_SHIELD:
  3882. case CHANNEL_WARD:
  3883. return channel_type - 4;
  3884. case CHANNEL_MELEE_COMBAT:
  3885. case CHANNEL_WARNINGS:
  3886. case CHANNEL_YOU_HIT:
  3887. case CHANNEL_YOU_MISS:
  3888. case CHANNEL_ATTACKER_HITS:
  3889. case CHANNEL_ATTACKER_MISSES:
  3890. case CHANNEL_YOUR_PET_HITS:
  3891. case CHANNEL_YOUR_PET_MISSES:
  3892. case CHANNEL_ATTACKER_HITS_PET:
  3893. case CHANNEL_ATTACKER_MISSES_PET:
  3894. case CHANNEL_OTHER_HIT:
  3895. case CHANNEL_OTHER_MISSES:
  3896. return channel_type - 5;
  3897. case CHANNEL_OTHER:
  3898. case CHANNEL_MONEY_SPLIT:
  3899. case CHANNEL_LOOT:
  3900. return channel_type - 14;
  3901. case CHANNEL_COMMAND_TEXT:
  3902. case CHANNEL_BROADCAST:
  3903. case CHANNEL_WHO:
  3904. case CHANNEL_COMMANDS:
  3905. case CHANNEL_MERCHANT:
  3906. case CHANNEL_MERCHANT_BUY_SELL:
  3907. case CHANNEL_CONSIDER_MESSAGE:
  3908. case CHANNEL_CON_MINUS_2:
  3909. case CHANNEL_CON_MINUS_1:
  3910. case CHANNEL_CON_0:
  3911. case CHANNEL_CON_1:
  3912. case CHANNEL_CON_2:
  3913. case CHANNEL_TRADESKILLS:
  3914. case CHANNEL_HARVESTING:
  3915. case CHANNEL_HARVESTING_WARNINGS:
  3916. return channel_type - 15;
  3917. default: {
  3918. return CHANNEL_DEFAULT;
  3919. }
  3920. }
  3921. }
  3922. else {
  3923. switch (channel_type) {
  3924. default: {
  3925. return channel_type;
  3926. }
  3927. }
  3928. }
  3929. return channel_type;
  3930. }
  3931. void Client::HandleTellMessage(Client* from, const char* message, const char* to, int32 current_language_id) {
  3932. if (!from || GetPlayer()->IsIgnored(from->GetPlayer()->GetName()))
  3933. return;
  3934. PacketStruct* packet = configReader.getStruct("WS_HearChat", GetVersion());
  3935. if (packet) {
  3936. packet->setDataByName("from", from->GetPlayer()->GetName());
  3937. packet->setDataByName("to", to);
  3938. packet->setDataByName("channel", GetMessageChannelColor(CHANNEL_PRIVATE_TELL));
  3939. packet->setDataByName("from_spawn_id", 0xFFFFFFFF);
  3940. packet->setDataByName("to_spawn_id", 0xFFFFFFFF);
  3941. packet->setDataByName("unknown2", 1, 1);
  3942. packet->setDataByName("show_bubble", 1);
  3943. if (current_language_id == 0 || GetPlayer()->HasLanguage(current_language_id)) {
  3944. packet->setDataByName("understood", 1);
  3945. }
  3946. packet->setDataByName("time", 2);
  3947. packet->setDataByName("language", current_language_id);
  3948. packet->setMediumStringByName("message", message);
  3949. EQ2Packet* outpacket = packet->serialize();
  3950. QueuePacket(outpacket);
  3951. safe_delete(packet);
  3952. }
  3953. }
  3954. void Client::SimpleMessage(int8 color, const char* message) {
  3955. PacketStruct* command_packet = configReader.getStruct("WS_DisplayText", GetVersion());
  3956. if (command_packet) {
  3957. command_packet->setDataByName("color", GetMessageChannelColor(color));//convert this to the correct client type (different clients have different chat numbers)
  3958. command_packet->setMediumStringByName("text", message);
  3959. command_packet->setDataByName("unknown02", 0x00ff);
  3960. EQ2Packet* outapp = command_packet->serialize();
  3961. QueuePacket(outapp);
  3962. safe_delete(command_packet);
  3963. }
  3964. }
  3965. void Client::SendSpellUpdate(Spell* spell, bool add_silently, bool add_to_hotbar) {
  3966. PacketStruct* packet = configReader.getStruct("WS_SpellGainedMsg", GetVersion());
  3967. if (packet) {
  3968. int8 xxx = spell->GetSpellData()->is_aa;
  3969. packet->setDataByName("spell_type", spell->GetSpellData()->type);
  3970. packet->setDataByName("spell_id", spell->GetSpellID());
  3971. packet->setDataByName("unique_id", spell->GetSpellData()->spell_name_crc);
  3972. packet->setDataByName("spell_name", spell->GetName());
  3973. if(add_silently)
  3974. packet->setDataByName("add_silently", 1);
  3975. if(add_to_hotbar)
  3976. packet->setDataByName("add_to_hotbar", 1);
  3977. packet->setDataByName("unknown", xxx);
  3978. packet->setDataByName("display_spell_tier", 1);
  3979. packet->setDataByName("unknown3", 1);
  3980. packet->setDataByName("tier", spell->GetSpellTier());
  3981. packet->setDataByName("icon", spell->GetSpellIcon());
  3982. packet->setDataByName("icon_type", spell->GetSpellIconBackdrop());
  3983. packet->setDataByName("unknown5", 0xFFFFFFFF);
  3984. //packet->PrintPacket();
  3985. EQ2Packet* outapp = packet->serialize();
  3986. //DumpPacket(outapp);
  3987. QueuePacket(outapp);
  3988. safe_delete(packet);
  3989. }
  3990. }
  3991. void Client::Message(int8 type, const char* message, ...) {
  3992. va_list argptr;
  3993. char buffer[4096];
  3994. va_start(argptr, message);
  3995. vsnprintf(buffer, sizeof(buffer), message, argptr);
  3996. va_end(argptr);
  3997. SimpleMessage(type, buffer);
  3998. }
  3999. void Client::Disconnect(bool send_disconnect)
  4000. {
  4001. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client Disconnect...");
  4002. this->Save();
  4003. this->GetPlayer()->WritePlayerStatistics();
  4004. SetConnected(false);
  4005. if (send_disconnect && getConnection())
  4006. getConnection()->SendDisconnect(true);
  4007. eqs = 0;
  4008. }
  4009. bool Client::Summon(const char* search_name) {
  4010. Spawn* target = 0;
  4011. if (search_name || GetPlayer()->GetTarget()) {
  4012. Client* search_client = 0;
  4013. if (search_name) {
  4014. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  4015. if (target && target->IsPlayer())
  4016. search_client = target->GetClient();
  4017. if (!target) {
  4018. search_client = zone_list.GetClientByCharName(string(search_name));
  4019. if (search_client)
  4020. target = search_client->GetPlayer();
  4021. }
  4022. }
  4023. else
  4024. target = GetPlayer()->GetTarget();
  4025. if (target && target != GetPlayer()) {
  4026. target->SetX(GetPlayer()->GetX());
  4027. target->SetY(GetPlayer()->GetY());
  4028. target->SetZ(GetPlayer()->GetZ());
  4029. target->SetHeading(GetPlayer()->GetHeading());
  4030. if (!target->IsPlayer()) {
  4031. target->SetSpawnOrigX(target->GetX());
  4032. target->SetSpawnOrigY(target->GetY());
  4033. target->SetSpawnOrigZ(target->GetZ());
  4034. target->SetSpawnOrigHeading(target->GetHeading());
  4035. }
  4036. target->SetLocation(GetPlayer()->GetLocation());
  4037. if(target->IsNPC()) {
  4038. ((NPC*)target)->HaltMovement();
  4039. }
  4040. }
  4041. else if (target)
  4042. Message(CHANNEL_COLOR_RED, "Error: You cannot summon yourself!");
  4043. if (search_client && search_client != this) {
  4044. search_client->Message(CHANNEL_COLOR_YELLOW, "You have been summoned by '%s'!", GetPlayer()->GetName());
  4045. Message(CHANNEL_COLOR_YELLOW, "Summoning '%s'...", search_client->GetPlayer()->GetName());
  4046. if (search_client->GetCurrentZone() != GetCurrentZone())
  4047. search_client->Zone(GetCurrentZone()->GetZoneName(), false);
  4048. else {
  4049. EQ2Packet* app = search_client->GetPlayer()->Move(GetPlayer()->GetX(), GetPlayer()->GetY(), GetPlayer()->GetZ(), search_client->GetVersion());
  4050. if (app)
  4051. search_client->QueuePacket(app);
  4052. }
  4053. }
  4054. }
  4055. if (!target)
  4056. return false;
  4057. else
  4058. return true;
  4059. }
  4060. std::string Client::IdentifyInstanceLockout(int32 zoneID, bool displayClient) {
  4061. int8 instanceType = database.GetInstanceTypeByZoneID(zoneID);
  4062. if(instanceType < 1)
  4063. return std::string("");
  4064. ZoneServer* instance_zone = nullptr;
  4065. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  4066. if (data) {
  4067. // If lockout instances check to see if we are locked out
  4068. if (instanceType == SOLO_LOCKOUT_INSTANCE || instanceType == GROUP_LOCKOUT_INSTANCE || instanceType == RAID_LOCKOUT_INSTANCE) {
  4069. int32 time = 0;
  4070. // Check success timer
  4071. if (data->last_success_timestamp > 0) {
  4072. if (Timer::GetUnixTimeStamp() < data->last_success_timestamp + data->success_lockout_time) {
  4073. // Timer has not expired yet can't re enter
  4074. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Success lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  4075. time = (data->last_success_timestamp + data->success_lockout_time) - Timer::GetUnixTimeStamp();
  4076. }
  4077. }
  4078. // Check failure timer
  4079. if (data->last_failure_timestamp > 0) {
  4080. if (Timer::GetUnixTimeStamp() < data->last_failure_timestamp + data->failure_lockout_time) {
  4081. // Timer has not expired yet
  4082. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Failure lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  4083. time = (data->last_failure_timestamp + data->failure_lockout_time) - Timer::GetUnixTimeStamp();
  4084. }
  4085. }
  4086. // Time > 0 then we are locked out, make the message and send it and return true
  4087. if (time > 0) {
  4088. string time_msg = "";
  4089. int16 hour;
  4090. int8 min;
  4091. int8 sec;
  4092. hour = time / 3600;
  4093. time = time % 3600;
  4094. min = time / 60;
  4095. time = time % 60;
  4096. sec = time;
  4097. if (hour > 0) {
  4098. char temp[10];
  4099. snprintf(temp, 9," %i", hour);
  4100. time_msg.append(temp);
  4101. time_msg.append(" hour");
  4102. time_msg.append((hour > 1) ? "s" : "");
  4103. }
  4104. if (min > 0) {
  4105. char temp[5];
  4106. snprintf(temp, 4," %i", min);
  4107. time_msg.append(temp);
  4108. time_msg.append(" minute");
  4109. time_msg.append((min > 1) ? "s" : "");
  4110. }
  4111. // Only add seconds if minutes and hours are 0
  4112. if (hour == 0 && min == 0 && sec > 0) {
  4113. char temp[5];
  4114. snprintf(temp, 4," %i", sec);
  4115. time_msg.append(temp);
  4116. time_msg.append(" second");
  4117. time_msg.append((sec > 1) ? "s" : "");
  4118. }
  4119. if(displayClient)
  4120. Message(CHANNEL_COLOR_YELLOW, "You may not enter again for%s.", time_msg.c_str());
  4121. return time_msg;
  4122. }
  4123. }
  4124. }
  4125. return std::string("");
  4126. }
  4127. ZoneServer* Client::IdentifyInstance(int32 zoneID) {
  4128. int8 instanceType = database.GetInstanceTypeByZoneID(zoneID);
  4129. if(instanceType < 1)
  4130. return nullptr;
  4131. ZoneServer* instance_zone = nullptr;
  4132. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  4133. if (data) {
  4134. std::string lockoutTime = IdentifyInstanceLockout(zoneID);
  4135. // If lockout instances check to see if we are locked out
  4136. if (lockoutTime.length() > 0) {
  4137. return nullptr;
  4138. }
  4139. // Need to update `character_instances` table with new timestamps (for persistent) and instance id's
  4140. instance_zone = zone_list.GetByInstanceID(data->instance_id, zoneID, false, false);
  4141. // 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
  4142. if (instance_zone && (data->instance_id == 0 || data->instance_id != instance_zone->GetInstanceID())) {
  4143. if (instanceType == SOLO_PERSIST_INSTANCE || instanceType == GROUP_PERSIST_INSTANCE || instanceType == RAID_PERSIST_INSTANCE) {
  4144. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  4145. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  4146. }
  4147. else
  4148. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID());
  4149. data->instance_id = instance_zone->GetInstanceID();
  4150. }
  4151. }
  4152. return instance_zone;
  4153. }
  4154. bool Client::TryZoneInstance(int32 zoneID, bool zone_coords_valid) {
  4155. ZoneServer* instance_zone = NULL;
  4156. int8 instanceType = 0;
  4157. // determine if this is a group instanced zone that already exists
  4158. instance_zone = GetPlayer()->GetGroupMemberInZone(zoneID);
  4159. if (instance_zone != NULL)
  4160. Zone(instance_zone->GetInstanceID(), zone_coords_valid);
  4161. else if ((instanceType = database.GetInstanceTypeByZoneID(zoneID)) > 0)
  4162. {
  4163. // best to check if we already have our own instance!
  4164. if((instance_zone = IdentifyInstance(zoneID)) == nullptr)
  4165. {
  4166. switch (instanceType)
  4167. {
  4168. case SOLO_LOCKOUT_INSTANCE:
  4169. case GROUP_LOCKOUT_INSTANCE:
  4170. case RAID_LOCKOUT_INSTANCE:
  4171. {
  4172. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4173. if (instance_zone) {
  4174. // 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
  4175. // so delete `instances` entry for the zone when it shuts down.
  4176. 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());
  4177. if (db_id > 0)
  4178. GetPlayer()->GetCharacterInstances()->AddInstance(db_id, instance_zone->GetInstanceID(), 0, 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime(), zoneID, instance_zone->GetInstanceType(), string(instance_zone->GetZoneName()));
  4179. }
  4180. break;
  4181. }
  4182. case SOLO_PERSIST_INSTANCE:
  4183. case GROUP_PERSIST_INSTANCE:
  4184. case RAID_PERSIST_INSTANCE:
  4185. {
  4186. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4187. if (instance_zone) {
  4188. 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());
  4189. if (db_id > 0)
  4190. 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()));
  4191. }
  4192. break;
  4193. }
  4194. case PUBLIC_INSTANCE:
  4195. case TRADESKILL_INSTANCE:
  4196. {
  4197. // if its public/tradeskill, look for a public already setup
  4198. instance_zone = zone_list.GetByLowestPopulation(zoneID);
  4199. if (instance_zone) {
  4200. // Check the current population against the max population, if greater or equal start a new version
  4201. if (instance_zone->GetClientCount() >= rule_manager.GetGlobalRule(R_Zone, MaxPlayers)->GetInt32())
  4202. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4203. }
  4204. else
  4205. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4206. break;
  4207. }
  4208. case PERSONAL_HOUSE_INSTANCE:
  4209. case GUILD_HOUSE_INSTANCE:
  4210. {
  4211. // Because of the way housing works (need to load a specific instance id supplied in a packet) we can't
  4212. // use this function without some rework, so it will all be handled in Client::HandlePacket()
  4213. // with the OP_EnterHouseMsg opcode
  4214. break;
  4215. }
  4216. case QUEST_INSTANCE:
  4217. {
  4218. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4219. break;
  4220. /*
  4221. 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`;
  4222. */
  4223. }
  4224. default:
  4225. {
  4226. // NONE
  4227. }
  4228. }
  4229. }
  4230. if (instance_zone != NULL)
  4231. Zone(instance_zone, zone_coords_valid);
  4232. }
  4233. if (instance_zone != NULL)
  4234. return true;
  4235. else
  4236. return false;
  4237. }
  4238. bool Client::GotoSpawn(const char* search_name, bool forceTarget) {
  4239. Spawn* target = 0;
  4240. if (search_name || GetPlayer()->GetTarget()) {
  4241. Client* search_client = 0;
  4242. if (search_name) {
  4243. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  4244. if (!target) {
  4245. search_client = zone_list.GetClientByCharName(search_name);
  4246. if (search_client)
  4247. target = search_client->GetPlayer();
  4248. }
  4249. if (target)
  4250. GetPlayer()->SetTarget(target);
  4251. }
  4252. else
  4253. target = GetPlayer()->GetTarget();
  4254. if (target && target != GetPlayer()) {
  4255. GetPlayer()->SetX(target->GetX());
  4256. GetPlayer()->SetY(target->GetY());
  4257. GetPlayer()->SetZ(target->GetZ());
  4258. GetPlayer()->SetHeading(target->GetHeading());
  4259. GetPlayer()->SetLocation(target->GetLocation());
  4260. Message(CHANNEL_COLOR_YELLOW, "Warping to '%s'", target->GetName());
  4261. }
  4262. else if (target)
  4263. Message(CHANNEL_COLOR_RED, "Error: You cannot goto yourself!");
  4264. if (search_client && search_client->GetCurrentZone() != GetCurrentZone())
  4265. Zone(search_client->GetCurrentZone()->GetZoneName(), false);
  4266. else if (target) {
  4267. EQ2Packet* app = GetPlayer()->Move(target->GetX(), target->GetY(), target->GetZ(), GetVersion(), (target->GetHeading() + 180.0f));
  4268. if (app)
  4269. QueuePacket(app);
  4270. }
  4271. }
  4272. if (!target)
  4273. return false;
  4274. else
  4275. return true;
  4276. }
  4277. bool Client::CheckZoneAccess(const char* zoneName) {
  4278. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone access check for %s (%u), client: %u", zoneName, database.GetZoneID(zoneName), GetVersion());
  4279. ZoneServer* zone = zone_list.Get(zoneName, false, false, false);
  4280. // JA: implemented /zone lock|unlock commands (2012.07.28)
  4281. if (zone && zone->GetZoneLockState())
  4282. {
  4283. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone currently LOCKED: '%s' (%ul)", zoneName, zone->GetZoneID());
  4284. Message(CHANNEL_COLOR_RED, "This zone is locked, and you don't have the key! (%s).", zoneName);
  4285. return false;
  4286. }
  4287. sint16 zoneMinStatus = 0;
  4288. int16 zoneMinLevel = 0;
  4289. int16 zoneMaxLevel = 0;
  4290. int16 zoneMinVersion = 0;
  4291. if (!zone)
  4292. {
  4293. LogWrite(CCLIENT__DEBUG, 0, "Client", "Grabbing zone requirements for %s", zoneName);
  4294. bool success = database.GetZoneRequirements(zoneName, &zoneMinStatus, &zoneMinLevel, &zoneMaxLevel, &zoneMinVersion);
  4295. if (!success) { // couldn't even find the zone, this shouldn't happen though..
  4296. return true;
  4297. }
  4298. }
  4299. else
  4300. {
  4301. zoneMinStatus = zone->GetMinimumStatus();
  4302. zoneMinLevel = zone->GetMinimumLevel();
  4303. zoneMaxLevel = zone->GetMaximumLevel();
  4304. zoneMinVersion = zone->GetMinimumVersion();
  4305. }
  4306. LogWrite(CCLIENT__DEBUG, 0, "Client", "Access Requirements: status %i, level %i - %i, req >= %i version", zoneMinStatus, zoneMinLevel, zoneMaxLevel, zoneMinVersion);
  4307. // use ZoneLevelOverrideStatus in both min_level and max_level checks
  4308. sint16 ZoneLevelOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneLevelOverrideStatus)->GetSInt16();
  4309. if ((zoneMinVersion > 0) && (GetVersion() < zoneMinVersion))
  4310. {
  4311. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinVersion of %i challenge...", zoneMinVersion);
  4312. Message(CHANNEL_COLOR_RED, "You do not have the required expansion pack to enter here (%s).", database.GetExpansionIDByVersion(zoneMinVersion).c_str());
  4313. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client denied access to zone '%s' (version req: %i)", zoneName, zoneMinVersion);
  4314. return false;
  4315. }
  4316. if ((zoneMinLevel > 1) && (player->GetLevel() < zoneMinLevel))
  4317. {
  4318. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  4319. {
  4320. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  4321. Message(CHANNEL_COLOR_RED, "Your level is too low to enter here (%s)", zoneMinLevel);
  4322. return false;
  4323. }
  4324. }
  4325. if ((zoneMaxLevel > 1) && (player->GetLevel() > zoneMaxLevel))
  4326. {
  4327. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  4328. {
  4329. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  4330. Message(CHANNEL_COLOR_RED, "Your level is too high to enter here (%s)", zoneMaxLevel);
  4331. return false;
  4332. }
  4333. }
  4334. if ((zoneMinStatus > 0) && (GetAdminStatus() < zoneMinStatus))
  4335. {
  4336. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinStatus of %i challenge...", zoneMinStatus);
  4337. sint16 ZoneAccessOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneAccessOverrideStatus)->GetSInt16();
  4338. if (ZoneAccessOverrideStatus && ZoneAccessOverrideStatus > GetAdminStatus())
  4339. {
  4340. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (status req: %i)", zoneName, GetAdminStatus());
  4341. Message(CHANNEL_COLOR_RED, "You do not have permission to enter here (%i).", zoneMinStatus);
  4342. return false;
  4343. }
  4344. }
  4345. return true;
  4346. }
  4347. void Client::Zone(int32 instanceid, bool set_coords, bool byInstanceID, bool is_spell) {
  4348. Zone(zone_list.GetByInstanceID(instanceid, 0, false, true), set_coords, is_spell);
  4349. }
  4350. void Client::Zone(ZoneServer* new_zone, bool set_coords, bool is_spell) {
  4351. if (!new_zone) {
  4352. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request Denied! No 'new_zone' value");
  4353. return;
  4354. }
  4355. if(GetVersion() == 373 && GetAdminStatus() == 0) {
  4356. if(strncasecmp(new_zone->GetZoneFile(),"boat_06p_tutorial02",19) && strncasecmp(new_zone->GetZoneFile(),"tutorial_island02",17)) {
  4357. SimpleMessage(CHANNEL_COLOR_RED, "This client does not currently support beyond the boat tutorial (farjourneyfreeport) or island of refuge (islerefuge1)");
  4358. return;
  4359. }
  4360. }
  4361. client_zoning = true;
  4362. zoning_id = new_zone->GetZoneID();
  4363. zoning_instance_id = new_zone->GetInstanceID();
  4364. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting player Resurrecting to 'true'", __FUNCTION__);
  4365. player->SetResurrecting(true);
  4366. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from fighting...", __FUNCTION__);
  4367. //GetCurrentZone()->GetCombat()->RemoveHate(player);
  4368. SaveSpells();
  4369. ResetSendMail();
  4370. // Remove players pet from zone if there is one
  4371. ((Entity*)player)->DismissAllPets();
  4372. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from current zone...", __FUNCTION__);
  4373. GetCurrentZone()->RemoveSpawn(player, false, true, true, true, !is_spell);
  4374. GetPlayer()->DeleteSpellEffects(true);
  4375. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting zone to '%s'...", __FUNCTION__, new_zone->GetZoneName());
  4376. SetZoningDestination(new_zone);
  4377. SetCurrentZone(new_zone);
  4378. if (player->GetGroupMemberInfo())
  4379. {
  4380. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Player in group, updating group info...", __FUNCTION__);
  4381. player->UpdateGroupMemberInfo();
  4382. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id, this);
  4383. }
  4384. // block out the member info for the group
  4385. TempRemoveGroup();
  4386. UpdateTimeStampFlag(ZONE_UPDATE_FLAG);
  4387. if (set_coords)
  4388. {
  4389. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Zoning player to coordinates x: %2f, y: %2f, z: %2f, heading: %2f in zone '%s'...",
  4390. __FUNCTION__,
  4391. GetCurrentZone()->GetSafeX(),
  4392. GetCurrentZone()->GetSafeY(),
  4393. GetCurrentZone()->GetSafeZ(),
  4394. GetCurrentZone()->GetSafeHeading(),
  4395. new_zone->GetZoneName()
  4396. );
  4397. player->SetX(GetCurrentZone()->GetSafeX());
  4398. player->SetY(GetCurrentZone()->GetSafeY());
  4399. player->SetZ(GetCurrentZone()->GetSafeZ());
  4400. player->SetHeading(GetCurrentZone()->GetSafeHeading());
  4401. SetZoningCoords(GetCurrentZone()->GetSafeX(), GetCurrentZone()->GetSafeY(),
  4402. GetCurrentZone()->GetSafeZ(), GetCurrentZone()->GetSafeHeading());
  4403. }
  4404. else {
  4405. ResetZoningCoords();
  4406. }
  4407. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Saving Player info...", __FUNCTION__);
  4408. Save();
  4409. char* new_zone_ip = 0;
  4410. if (IsPrivateAddress(this->GetIP()) && strlen(net.GetInternalWorldAddress()) > 0)
  4411. new_zone_ip = net.GetInternalWorldAddress();
  4412. else
  4413. new_zone_ip = net.GetWorldAddress();
  4414. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: New Zone IP '%s'...", __FUNCTION__, new_zone_ip);
  4415. int32 key = Timer::GetUnixTimeStamp();
  4416. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending ZoneChangeMsg...", __FUNCTION__);
  4417. ClientPacketFunctions::SendZoneChange(this, new_zone_ip, net.GetWorldPort(), key);
  4418. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending to zone_auth.AddAuth...", __FUNCTION__);
  4419. zone_auth.AddAuth(new ZoneAuthRequest(GetAccountID(), player->GetName(), key));
  4420. if (version > 373) {
  4421. PacketStruct* packet = configReader.getStruct("WS_CancelMoveObjectMode", version);
  4422. if (packet)
  4423. {
  4424. QueuePacket(packet->serialize());
  4425. safe_delete(packet);
  4426. }
  4427. }
  4428. }
  4429. void Client::Zone(const char* new_zone, bool set_coords, bool is_spell)
  4430. {
  4431. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request to '%s'", new_zone);
  4432. Zone(zone_list.Get(new_zone), set_coords, is_spell);
  4433. }
  4434. float Client::DistanceFrom(Client* client) {
  4435. float ret = 0;
  4436. if (client && client != this) {
  4437. ret = pow(player->GetX() - client->player->GetX(), 2) + pow(player->GetY() - client->player->GetY(), 2) + pow(player->GetZ() - client->player->GetZ(), 2);
  4438. ret = sqrt(ret);
  4439. }
  4440. return ret;
  4441. }
  4442. void Client::DetermineCharacterUpdates() {
  4443. ServerPacket* outpack = new ServerPacket(ServerOP_BasicCharUpdate, sizeof(CharDataUpdate_Struct));
  4444. CharDataUpdate_Struct* cdu = (CharDataUpdate_Struct*)outpack->pBuffer;
  4445. cdu->account_id = GetAccountID();
  4446. cdu->char_id = GetCharacterID();
  4447. int32 timestamp = Timer::GetUnixTimeStamp();
  4448. int8 flag = GetTimeStampFlag();
  4449. if (flag & LEVEL_UPDATE_FLAG)
  4450. {
  4451. cdu->update_field = LEVEL_UPDATE_FLAG;
  4452. cdu->update_data = player->GetLevel();
  4453. loginserver.SendPacket(outpack);
  4454. }
  4455. //if(flag&CLASS_UPDATE_FLAG && player->GetLevel() >= 20)// Perseverance only
  4456. if (flag & CLASS_UPDATE_FLAG)
  4457. {
  4458. cdu->update_field = CLASS_UPDATE_FLAG;
  4459. cdu->update_data = player->GetAdventureClass();
  4460. loginserver.SendPacket(outpack);
  4461. }
  4462. if (flag & GENDER_UPDATE_FLAG)
  4463. {
  4464. cdu->update_field = GENDER_UPDATE_FLAG;
  4465. cdu->update_data = player->GetGender();
  4466. loginserver.SendPacket(outpack);
  4467. }
  4468. if (flag & DELETE_UPDATE_FLAG) {
  4469. LogWrite(MISC__TODO, 1, "TODO", "Delete update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  4470. }
  4471. safe_delete(outpack); // Zone, armor and name use a different structure
  4472. if (flag & RACE_UPDATE_FLAG)
  4473. {
  4474. outpack = new ServerPacket(ServerOP_RaceUpdate, sizeof(RaceUpdate_Struct));
  4475. RaceUpdate_Struct* ru = (RaceUpdate_Struct*)outpack->pBuffer;
  4476. ru->account_id = GetAccountID();
  4477. ru->char_id = GetCharacterID();
  4478. ru->race = player->GetRace();
  4479. ru->model_type = player->GetModelType();
  4480. loginserver.SendPacket(outpack);
  4481. safe_delete(outpack);
  4482. }
  4483. if (flag & ZONE_UPDATE_FLAG) {
  4484. ServerPacket* outpack = new ServerPacket(ServerOP_ZoneUpdate, CHARZONESTRUCT_MAXSIZE);
  4485. memset(outpack->pBuffer, 0, CHARZONESTRUCT_MAXSIZE);
  4486. CharZoneUpdate_Struct* czu = (CharZoneUpdate_Struct*)outpack->pBuffer;
  4487. czu->account_id = GetAccountID();
  4488. czu->char_id = GetCharacterID();
  4489. czu->zone_id = GetCurrentZone()->GetZoneID();
  4490. const char* zone_file = GetCurrentZone()->GetZoneFile();
  4491. czu->zone_length = strlen(zone_file);
  4492. if (czu->zone_length > 64)
  4493. czu->zone_length = 64;
  4494. strncpy(czu->new_zone, zone_file, czu->zone_length);
  4495. loginserver.SendPacket(outpack);
  4496. safe_delete(outpack);
  4497. }
  4498. if (flag & ARMOR_UPDATE_FLAG) {
  4499. LogWrite(MISC__TODO, 1, "TODO", "Armor update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  4500. }
  4501. if (flag & NAME_UPDATE_FLAG) {
  4502. LogWrite(MISC__TODO, 1, "TODO", "Name update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  4503. }
  4504. database.UpdateCharacterTimeStamp(GetAccountID(), GetCharacterID(), timestamp);
  4505. }
  4506. void Client::Save() {
  4507. if (GetCharacterID() == 0 || IsSaveDisabled())
  4508. return;
  4509. if (current_zone) {
  4510. DetermineCharacterUpdates();
  4511. UpdateCharacterInstances();
  4512. this->SetLastSavedTimeStamp(Timer::GetCurrentTime2());
  4513. database.Save(this);
  4514. if (GetPlayer()->UpdateQuickbarNeeded()) {
  4515. database.SaveQuickBar(GetCharacterID(), GetPlayer()->GetQuickbar());
  4516. GetPlayer()->ResetQuickbarNeeded();
  4517. }
  4518. database.SaveItems(this);
  4519. database.SaveBuyBacks(this);
  4520. GetPlayer()->SaveHistory();
  4521. GetPlayer()->SaveLUAHistory();
  4522. MSaveSpellStateMutex.lock();
  4523. GetPlayer()->SaveSpellEffects();
  4524. MSaveSpellStateMutex.unlock();
  4525. }
  4526. }
  4527. void Client::UpdateCharacterInstances() {
  4528. if (GetPlayer() != NULL)
  4529. GetPlayer()->GetCharacterInstances()->ProcessInstanceTimers(GetPlayer());
  4530. /*if ( GetPlayer() != NULL )
  4531. {
  4532. // determine the last timestamp then get a new one, determine the difference in the timestamp
  4533. // to use for applying the update to each instances timer
  4534. int32 lastSaveTS = GetLastSavedTimeStamp();
  4535. int32 newSaveTS = Timer::GetUnixTimeStamp();
  4536. int32 diffTS = newSaveTS - lastSaveTS;
  4537. // update instance timers
  4538. GetPlayer()->GetCharacterInstances().ProcessInstanceTimers(GetPlayer(),diffTS);
  4539. // update with the new timestamp and save the db
  4540. this->SetLastSavedTimeStamp(newSaveTS);
  4541. }*/
  4542. }
  4543. void Client::HandleVerbRequest(EQApplicationPacket* app) {
  4544. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsRequest", GetVersion());
  4545. if (packet) {
  4546. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  4547. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  4548. PacketStruct* out = configReader.getStruct("WS_EntityVerbsResponse", GetVersion());
  4549. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(spawn_id);
  4550. vector<EntityCommand*> commands;
  4551. vector<EntityCommand*> delete_commands;
  4552. if (out && spawn) {
  4553. for (int32 i = 0; i < spawn->primary_command_list.size(); i++)
  4554. {
  4555. // default is a deny list not allow, only allow if on the iterator list and itr second is not false (deny)
  4556. if (!spawn->primary_command_list[i]->default_allow_list)
  4557. {
  4558. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  4559. if (itr == spawn->primary_command_list[i]->allow_or_deny.end() || !itr->second)
  4560. continue;
  4561. }
  4562. else
  4563. {
  4564. // default is allow list, only deny if added to the list as deny (false itr second)
  4565. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  4566. if (itr != spawn->primary_command_list[i]->allow_or_deny.end() && !itr->second)
  4567. continue;
  4568. }
  4569. commands.push_back(spawn->primary_command_list[i]);
  4570. }
  4571. for (int32 i = 0; i < spawn->secondary_command_list.size(); i++)
  4572. commands.push_back(spawn->secondary_command_list[i]);
  4573. if (spawn->IsPlayer()) {
  4574. if (player->IsFriend(spawn->GetName()))
  4575. delete_commands.push_back(player->CreateEntityCommand("remove from friends list", 10000, "friend_remove", "", 0, 0));
  4576. else
  4577. delete_commands.push_back(player->CreateEntityCommand("add to friends list", 10000, "friend_add", "", 0, 0));
  4578. if (player->IsIgnored(spawn->GetName()))
  4579. delete_commands.push_back(player->CreateEntityCommand("remove from ignore list", 10000, "ignore_remove", "", 0, 0));
  4580. else
  4581. {
  4582. delete_commands.push_back(player->CreateEntityCommand("add to ignore list", 10000, "ignore_add", "", 0, 0));
  4583. delete_commands.push_back(player->CreateEntityCommand("Trade", 10, "start_trade", "", 0, 0));
  4584. }
  4585. if (((Player*)spawn)->GetGroupMemberInfo()) {
  4586. if (player->IsGroupMember((Player*)spawn) && player->GetGroupMemberInfo()->leader) { //group leader
  4587. delete_commands.push_back(player->CreateEntityCommand("kick from group", 10000, "kickfromgroup", "", 0, 0));
  4588. delete_commands.push_back(player->CreateEntityCommand("make group leader", 10000, "makeleader", "", 0, 0));
  4589. }
  4590. if(spawn->IsPlayer() && player->GetGroupMemberInfo() && !player->GetGroupMemberInfo()->mentor_target_char_id)
  4591. delete_commands.push_back(player->CreateEntityCommand("Mentor", 10000, "mentor", "", 0, 0));
  4592. else if(spawn->IsPlayer() && player->GetGroupMemberInfo() && player->GetGroupMemberInfo()->mentor_target_char_id == ((Player*)spawn)->GetCharacterID())
  4593. delete_commands.push_back(player->CreateEntityCommand("Stop Mentoring", 10000, "unmentor", "", 0, 0));
  4594. }
  4595. else if (!player->GetGroupMemberInfo() || (player->GetGroupMemberInfo()->leader && world.GetGroupManager()->GetGroupSize(player->GetGroupMemberInfo()->group_id) < 6))
  4596. delete_commands.push_back(player->CreateEntityCommand("invite to group", 10000, "invite", "", 0, 0));
  4597. commands.insert(commands.end(), delete_commands.begin(), delete_commands.end());
  4598. }
  4599. out->setDataByName("spawn_id", spawn_id);
  4600. out->setArrayLengthByName("num_verbs", commands.size());
  4601. for (int32 i = 0; i < commands.size(); i++) {
  4602. out->setArrayDataByName("command", commands[i]->command.c_str(), i);
  4603. out->setArrayDataByName("distance", commands[i]->distance, i);
  4604. if (commands[i]->error_text.length() == 0)
  4605. out->setArrayAddToPacketByName("error", false, i);
  4606. else {
  4607. out->setArrayDataByName("display_error", 1, i);
  4608. out->setArrayDataByName("error", commands[i]->error_text.c_str(), i);
  4609. }
  4610. out->setArrayDataByName("display_text", commands[i]->name.c_str(), i);
  4611. }
  4612. EQ2Packet* outapp = out->serialize();
  4613. //DumpPacket(outapp);
  4614. QueuePacket(outapp);
  4615. safe_delete(out);
  4616. for (int32 i = 0; i < delete_commands.size(); i++) {
  4617. safe_delete(delete_commands[i]);
  4618. }
  4619. }
  4620. }
  4621. safe_delete(packet);
  4622. }
  4623. }
  4624. void Client::SkillChanged(Skill* skill, int16 previous_value, int16 new_value) {
  4625. if (previous_value != new_value) {
  4626. 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);
  4627. char tmp[200] = { 0 };
  4628. 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);
  4629. SendPopupMessage(6, tmp, new_value > previous_value ? "skill_up" : "skill_down", 2.75f, 0xFF, 0xFF, 0xFF);
  4630. }
  4631. }
  4632. void Client::SendPopupMessage(int8 unknown, const char* text, const char* type, float size, int8 red, int8 green, int8 blue)
  4633. {
  4634. /* JA notes on the unknown:
  4635. 2 = ding glimmer
  4636. 16 = Achievement Unlocked
  4637. 6 no longer does anything
  4638. */
  4639. PacketStruct* packet = configReader.getStruct("WS_OnScreenMsg", GetVersion());
  4640. if (packet) {
  4641. packet->setDataByName("unknown", unknown);
  4642. packet->setMediumStringByName("text", text);
  4643. if (type && strlen(type) > 0)
  4644. packet->setMediumStringByName("message_type", type);
  4645. packet->setDataByName("size", size);
  4646. packet->setDataByName("red", red);
  4647. packet->setDataByName("green", green);
  4648. packet->setDataByName("blue", blue);
  4649. QueuePacket(packet->serialize());
  4650. safe_delete(packet);
  4651. }
  4652. }
  4653. void Client::ChangeLevel(int16 old_level, int16 new_level) {
  4654. if (new_level < 1) {
  4655. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  4656. return;
  4657. }
  4658. if (player->GetLevel() != new_level) {
  4659. player->SetLevel(new_level);
  4660. if (player->GetGroupMemberInfo()) {
  4661. player->UpdateGroupMemberInfo();
  4662. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  4663. }
  4664. }
  4665. if (new_level > old_level) {
  4666. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_ADVENTURE, new_level, player->GetAdventureClass());
  4667. }
  4668. if (player->GetPet()) {
  4669. NPC* pet = (NPC*)player->GetPet();
  4670. if (pet->GetMaxPetLevel() == 0 || new_level <= pet->GetMaxPetLevel()) {
  4671. pet->SetLevel(new_level);
  4672. pet->UpdateWeapons();
  4673. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4674. if (command_packet) {
  4675. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(pet));
  4676. command_packet->setDataByName("anim_type", 1753);
  4677. QueuePacket(command_packet->serialize());
  4678. safe_delete(command_packet);
  4679. }
  4680. }
  4681. }
  4682. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  4683. if (level_update) {
  4684. level_update->setDataByName("old_level", old_level);
  4685. level_update->setDataByName("new_level", new_level);
  4686. QueuePacket(level_update->serialize());
  4687. safe_delete(level_update);
  4688. GetCurrentZone()->StartZoneSpawnsForLevelThread(this);
  4689. GetCurrentZone()->SendCastSpellPacket(322, player, player); //send level up spell effect
  4690. //GetCurrentZone()->SendAllSpawnsForLevelChange(this);
  4691. }
  4692. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4693. if (command_packet) {
  4694. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  4695. command_packet->setDataByName("anim_type", 1753);
  4696. QueuePacket(command_packet->serialize());
  4697. safe_delete(command_packet);
  4698. }
  4699. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && new_level >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  4700. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  4701. SendNewAdventureSpells();
  4702. GetPlayer()->GetInfoStruct()->set_level(new_level);
  4703. GetPlayer()->UpdateWeapons();
  4704. // GetPlayer()->SetLevel(new_level);
  4705. 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__);
  4706. GetPlayer()->CalculatePlayerHPPower();
  4707. GetPlayer()->CalculateBonuses();
  4708. GetPlayer()->SetHP(GetPlayer()->GetTotalHP());
  4709. GetPlayer()->SetPower(GetPlayer()->GetTotalPower());
  4710. /*InfoStruct* info = player->GetInfoStruct();
  4711. info->set_agi_base(new_level * 2 + 15);
  4712. info->set_intel_base(new_level * 2 + 15);
  4713. info->set_wis_base(new_level * 2 + 15);
  4714. info->set_str_base(new_level * 2 + 15);
  4715. info->set_sta_base(new_level * 2 + 15);
  4716. info->set_cold_base((int16)(new_level * 1.5 + 10));
  4717. info->set_heat_base((int16)(new_level * 1.5 + 10));
  4718. info->set_disease_base((int16)(new_level * 1.5 + 10));
  4719. info->set_mental_base((int16)(new_level * 1.5 + 10));
  4720. info->set_magic_base((int16)(new_level * 1.5 + 10));
  4721. info->set_divine_base((int16)(new_level * 1.5 + 10));
  4722. info->set_poison_base((int16)(new_level * 1.5 + 10));
  4723. GetPlayer()->GetInfoStruct()->set_poison_base((int16)(new_level * 1.5 + 10));*/
  4724. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  4725. GetPlayer()->SetCharSheetChanged(true);
  4726. Message(CHANNEL_REWARD, "You are now level %i!", new_level);
  4727. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  4728. int16 new_skill_cap = 5 * new_level;
  4729. PlayerSkillList* player_skills = player->GetSkills();
  4730. player_skills->SetSkillCapsByType(SKILL_TYPE_ARMOR, new_skill_cap);
  4731. player_skills->SetSkillCapsByType(SKILL_TYPE_SHIELD, new_skill_cap);
  4732. if(rule_manager.GetGlobalRule(R_Player, AutoSkillUpBaseSkills)->GetBool()) {
  4733. //SKILL_TYPE_ARMOR/SKILL_TYPE_SHIELD always has the same current / max values
  4734. player_skills->SetSkillValuesByType(SKILL_TYPE_ARMOR, new_skill_cap, false);
  4735. player_skills->SetSkillValuesByType(SKILL_TYPE_SHIELD, new_skill_cap, false);
  4736. }
  4737. player_skills->SetSkillCapsByType(SKILL_TYPE_CLASS, new_skill_cap);
  4738. player_skills->SetSkillCapsByType(SKILL_TYPE_WEAPON, new_skill_cap);
  4739. if(rule_manager.GetGlobalRule(R_Player, AutoSkillUpBaseSkills)->GetBool()) {
  4740. //SKILL_TYPE_CLASS/SKILL_TYPE_WEAPON always has the same current/max values
  4741. player_skills->SetSkillValuesByType(SKILL_TYPE_CLASS, new_skill_cap, false);
  4742. player_skills->SetSkillValuesByType(SKILL_TYPE_WEAPON, new_skill_cap, false);
  4743. }
  4744. player_skills->SetSkillCapsByType(SKILL_TYPE_COMBAT, new_skill_cap);
  4745. player_skills->SetSkillCapsByType(SKILL_TYPE_GENERAL, new_skill_cap);
  4746. player_skills->SetSkillCapsByType(SKILL_TYPE_SPELLCASTING, new_skill_cap);
  4747. player_skills->SetSkillCapsByType(SKILL_TYPE_AVOIDANCE, new_skill_cap);
  4748. player_skills->SetSkillCapsByType(SKILL_TYPE_WEAPONRY, new_skill_cap);
  4749. if (new_level > player->GetTSLevel())
  4750. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, new_skill_cap);
  4751. //SKILL_ID_DUALWIELD, SKILL_ID_FISTS, SKILL_ID_DESTROYING, and SKILL_ID_MAGIC_AFFINITY always have the current_val equal to max_val
  4752. if (player_skills->HasSkill(SKILL_ID_DUALWIELD))
  4753. player_skills->SetSkill(SKILL_ID_DUALWIELD, new_skill_cap);
  4754. if (player_skills->HasSkill(SKILL_ID_FISTS))
  4755. player_skills->SetSkill(SKILL_ID_FISTS, new_skill_cap);
  4756. if (player_skills->HasSkill(SKILL_ID_DESTROYING))
  4757. player_skills->SetSkill(SKILL_ID_DESTROYING, new_skill_cap);
  4758. if (player_skills->HasSkill(SKILL_ID_MAGIC_AFFINITY))
  4759. player_skills->SetSkill(SKILL_ID_MAGIC_AFFINITY, new_skill_cap);
  4760. Guild* guild = GetPlayer()->GetGuild();
  4761. if (guild) {
  4762. int8 event_type = 0;
  4763. if (new_level < 10)
  4764. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_1_10;
  4765. else if (new_level == 10)
  4766. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_10;
  4767. else if (new_level >= 11 && new_level < 20)
  4768. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_11_20;
  4769. else if (new_level == 20)
  4770. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_20;
  4771. else if (new_level >= 21 && new_level < 30)
  4772. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_21_30;
  4773. else if (new_level == 30)
  4774. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_30;
  4775. else if (new_level >= 31 && new_level < 40)
  4776. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_31_40;
  4777. else if (new_level == 40)
  4778. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_40;
  4779. else if (new_level >= 41 && new_level < 50)
  4780. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_41_50;
  4781. else if (new_level == 50)
  4782. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_50;
  4783. else if (new_level >= 51 && new_level < 60)
  4784. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_51_60;
  4785. else if (new_level == 60)
  4786. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_60;
  4787. else if (new_level >= 61 && new_level < 70)
  4788. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_61_70;
  4789. else if (new_level == 70)
  4790. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_70;
  4791. else if (new_level >= 71 && new_level < 80)
  4792. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_71_80;
  4793. else if (new_level == 80)
  4794. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_80;
  4795. 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());
  4796. 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());
  4797. guild->UpdateGuildMemberInfo(GetPlayer());
  4798. guild->SendGuildMember(GetPlayer());
  4799. guild->SendGuildMemberList();
  4800. }
  4801. // Need to send the trait list every time the players level changes
  4802. // Also need to force the char sheet update or else there can be a large delay from when you level
  4803. // to when you are actually able to select traits.
  4804. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  4805. GetPlayer()->need_trait_update = true;
  4806. if (version > 561) {
  4807. QueuePacket(master_trait_list.GetTraitListPacket(this));
  4808. master_aa_list.DisplayAA(this, 0, 0);
  4809. }
  4810. else
  4811. master_trait_list.ChooseNextTrait(this);
  4812. if (GetPlayer()->SpawnedBots.size() > 0) {
  4813. map<int32, int32>::iterator itr;
  4814. for (itr = GetPlayer()->SpawnedBots.begin(); itr != GetPlayer()->SpawnedBots.end(); itr++) {
  4815. Spawn* bot = GetCurrentZone()->GetSpawnByID(itr->second);
  4816. if (bot && bot->IsBot())
  4817. ((Bot*)bot)->ChangeLevel(old_level, new_level);
  4818. }
  4819. }
  4820. if (GetPlayer()->GetHP() < GetPlayer()->GetTotalHP() || GetPlayer()->GetPower() < GetPlayer()->GetTotalPower())
  4821. GetPlayer()->GetZone()->AddDamagedSpawn(GetPlayer());
  4822. }
  4823. void Client::ChangeTSLevel(int16 old_level, int16 new_level) {
  4824. if (new_level < 1) {
  4825. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  4826. return;
  4827. }
  4828. if ((player->GetTSLevel() >= 9 && player->GetTradeskillClass() == 1) || (player->GetTSLevel() >= 19 && (player->GetTradeskillClass() == 1 || player->GetTradeskillClass() == 2 || player->GetTradeskillClass() == 6 || player->GetTradeskillClass() == 10))) {
  4829. SimpleMessage(CHANNEL_COLOR_YELLOW, "You can not gain levels until you select your next class!");
  4830. return;
  4831. }
  4832. if (new_level > old_level)
  4833. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_TRADESKILL, new_level, player->GetTradeskillClass());
  4834. if (player->GetTSLevel() != new_level) {
  4835. player->SetTSLevel(new_level);
  4836. if (player->GetGroupMemberInfo()) {
  4837. player->UpdateGroupMemberInfo();
  4838. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  4839. }
  4840. }
  4841. // Only tradeskill skills should increace, and then only those related to your class
  4842. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  4843. if (level_update) {
  4844. level_update->setDataByName("old_level", old_level);
  4845. level_update->setDataByName("new_level", new_level);
  4846. level_update->setDataByName("type", 1);
  4847. QueuePacket(level_update->serialize());
  4848. safe_delete(level_update);
  4849. }
  4850. // provide new spells upon levelling
  4851. SendNewTradeskillSpells();
  4852. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4853. if (command_packet) {
  4854. command_packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  4855. command_packet->setDataByName("anim_type", 1753);
  4856. QueuePacket(command_packet->serialize());
  4857. safe_delete(command_packet);
  4858. }
  4859. GetPlayer()->GetInfoStruct()->set_tradeskill_level(new_level);
  4860. GetPlayer()->SetTSLevel(new_level);
  4861. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  4862. GetPlayer()->SetCharSheetChanged(true);
  4863. Message(CHANNEL_NARRATIVE, "Your tradeskill level is now %i!", new_level);
  4864. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  4865. PlayerSkillList* player_skills = player->GetSkills();
  4866. int16 specialize_skill_cap = new_level * 5;
  4867. int16 artisan_skill_cap = std::max<int16>(specialize_skill_cap, 49);
  4868. int16 specialize_10_skill_cap = std::max<int16>(specialize_skill_cap, 99);
  4869. int8 ts_class = player->GetTradeskillClass();
  4870. int8 base_ts_class = classes.GetSecondaryTSBaseClass(ts_class);
  4871. int32 skill_id_1, skill_id_2, skill_id_3;
  4872. switch (base_ts_class) {
  4873. case ARTISAN:
  4874. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4875. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4876. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4877. break;
  4878. case OUTFITTER:
  4879. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4880. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4881. skill_id_1 = SKILL_ID_TAILORING;
  4882. skill_id_2 = SKILL_ID_METALSHAPING;
  4883. skill_id_3 = SKILL_ID_METALWORKING;
  4884. if (ts_class == TAILOR) {
  4885. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4886. skill_id_1 = 0;
  4887. }
  4888. else if (ts_class == ARMORER) {
  4889. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4890. skill_id_2 = 0;
  4891. }
  4892. else if (ts_class == WEAPONSMITH) {
  4893. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4894. skill_id_3 = 0;
  4895. }
  4896. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4897. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4898. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4899. break;
  4900. case SCHOLAR:
  4901. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4902. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4903. skill_id_1 = SKILL_ID_SCRIBING;
  4904. skill_id_2 = SKILL_ID_CHEMISTRY;
  4905. skill_id_3 = SKILL_ID_ARTIFICING;
  4906. if (ts_class == SAGE) {
  4907. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4908. skill_id_1 = 0;
  4909. }
  4910. else if (ts_class == ALCHEMIST) {
  4911. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4912. skill_id_2 = 0;
  4913. }
  4914. else if (ts_class == JEWELER) {
  4915. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4916. skill_id_3 = 0;
  4917. }
  4918. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4919. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4920. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4921. break;
  4922. case CRAFTSMAN:
  4923. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4924. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4925. skill_id_1 = SKILL_ID_ARTISTRY;
  4926. skill_id_2 = SKILL_ID_FLETCHING;
  4927. skill_id_3 = SKILL_ID_SCULPTING;
  4928. if (ts_class == PROVISIONER) {
  4929. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4930. skill_id_1 = 0;
  4931. }
  4932. else if (ts_class == WOODWORKER) {
  4933. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4934. skill_id_2 = 0;
  4935. }
  4936. else if (ts_class == CARPENTER) {
  4937. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4938. skill_id_3 = 0;
  4939. }
  4940. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4941. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4942. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4943. break;
  4944. default:
  4945. break;
  4946. }
  4947. if (new_level > player->GetAdventureClass())
  4948. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, specialize_skill_cap);
  4949. Guild* guild = GetPlayer()->GetGuild();
  4950. if (guild) {
  4951. int8 event_type = 0;
  4952. if (new_level < 10)
  4953. event_type = GUILD_EVENT_GAINS_TS_LEVEL_1_10;
  4954. else if (new_level == 10)
  4955. event_type = GUILD_EVENT_GAINS_TS_LEVEL_10;
  4956. else if (new_level >= 11 && new_level < 20)
  4957. event_type = GUILD_EVENT_GAINS_TS_LEVEL_11_20;
  4958. else if (new_level == 20)
  4959. event_type = GUILD_EVENT_GAINS_TS_LEVEL_20;
  4960. else if (new_level >= 21 && new_level < 30)
  4961. event_type = GUILD_EVENT_GAINS_TS_LEVEL_21_30;
  4962. else if (new_level == 30)
  4963. event_type = GUILD_EVENT_GAINS_TS_LEVEL_30;
  4964. else if (new_level >= 31 && new_level < 40)
  4965. event_type = GUILD_EVENT_GAINS_TS_LEVEL_31_40;
  4966. else if (new_level == 40)
  4967. event_type = GUILD_EVENT_GAINS_TS_LEVEL_40;
  4968. else if (new_level >= 41 && new_level < 50)
  4969. event_type = GUILD_EVENT_GAINS_TS_LEVEL_41_50;
  4970. else if (new_level == 50)
  4971. event_type = GUILD_EVENT_GAINS_TS_LEVEL_50;
  4972. else if (new_level >= 51 && new_level < 60)
  4973. event_type = GUILD_EVENT_GAINS_TS_LEVEL_51_60;
  4974. else if (new_level == 60)
  4975. event_type = GUILD_EVENT_GAINS_TS_LEVEL_60;
  4976. else if (new_level >= 61 && new_level < 70)
  4977. event_type = GUILD_EVENT_GAINS_TS_LEVEL_61_70;
  4978. else if (new_level == 70)
  4979. event_type = GUILD_EVENT_GAINS_TS_LEVEL_70;
  4980. else if (new_level >= 71 && new_level < 80)
  4981. event_type = GUILD_EVENT_GAINS_TS_LEVEL_71_80;
  4982. else if (new_level == 80)
  4983. event_type = GUILD_EVENT_GAINS_TS_LEVEL_80;
  4984. 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());
  4985. 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());
  4986. guild->UpdateGuildMemberInfo(GetPlayer());
  4987. guild->SendGuildMember(GetPlayer());
  4988. guild->SendGuildMemberList();
  4989. }
  4990. // Need to send the trait list every time the players level changes
  4991. // Also need to force the char sheet update or else there can be a large delay from when you level
  4992. // to when you are actually able to select traits.
  4993. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  4994. QueuePacket(master_trait_list.GetTraitListPacket(this));
  4995. }
  4996. void Client::CloseLoot(int32 spawn_id) {
  4997. if (GetVersion() > 561) {
  4998. PacketStruct* packet = configReader.getStruct("WS_CloseWindow", GetVersion());
  4999. if (packet) {
  5000. packet->setDataByName("window_id", 4);
  5001. EQ2Packet* outapp = packet->serialize();
  5002. if (outapp) {
  5003. //DumpPacket(outapp);
  5004. QueuePacket(outapp);
  5005. }
  5006. safe_delete(packet);
  5007. }
  5008. }
  5009. if(spawn_id > 0){
  5010. PacketStruct* packet = configReader.getStruct("WS_StoppedLooting", GetVersion());
  5011. if (packet) {
  5012. packet->setDataByName("spawn_id", spawn_id);
  5013. EQ2Packet* outapp = packet->serialize();
  5014. if (outapp)
  5015. QueuePacket(outapp);
  5016. safe_delete(packet);
  5017. }
  5018. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(spawn_id);
  5019. if(spawn) {
  5020. spawn->CloseLoot(GetPlayer());
  5021. }
  5022. }
  5023. }
  5024. string Client::GetCoinMessage(int32 total_coins) {
  5025. if (total_coins == 0) {
  5026. return " 0 Copper";
  5027. }
  5028. char tmp[64] = { 0 };
  5029. string message = "";
  5030. int32 val = 0;
  5031. if (total_coins >= 1000000) {
  5032. val = total_coins / 1000000;
  5033. total_coins -= 1000000 * val;
  5034. sprintf(tmp, " %u Platinum", val);
  5035. message.append(tmp);
  5036. memset(tmp, 0, 64);
  5037. }
  5038. if (total_coins >= 10000) {
  5039. val = total_coins / 10000;
  5040. total_coins -= 10000 * val;
  5041. sprintf(tmp, " %u Gold", val);
  5042. message.append(tmp);
  5043. memset(tmp, 0, 64);
  5044. }
  5045. if (total_coins >= 100) {
  5046. val = total_coins / 100;
  5047. total_coins -= 100 * val;
  5048. sprintf(tmp, " %u Silver", val);
  5049. message.append(tmp);
  5050. memset(tmp, 0, 64);
  5051. }
  5052. if (total_coins > 0) {
  5053. sprintf(tmp, " %u Copper", (int32)total_coins);
  5054. message.append(tmp);
  5055. }
  5056. return message;
  5057. }
  5058. void Client::SendLootResponsePacket(int32 total_coins, vector<Item*>* items, Spawn* entity, bool ignore_loot_tier) {
  5059. if (!entity) {
  5060. CloseLoot(0);
  5061. return;
  5062. }
  5063. if (total_coins > 0) {
  5064. player->AddCoins(total_coins);
  5065. //PlaySound("coin_cha_ching");
  5066. string message = "";
  5067. if (entity->GetHP() == 0) {
  5068. message = "You loot ";
  5069. entity->SetLootCoins(0, false);
  5070. }
  5071. else
  5072. message = "You receive ";
  5073. message.append(GetCoinMessage(total_coins));
  5074. if (entity->GetHP() == 0)
  5075. message.append(" from the corpse of ").append(entity->GetName());
  5076. int8 type = CHANNEL_LOOT;
  5077. SimpleMessage(type, message.c_str());
  5078. }
  5079. entity->StartLootTimer(GetPlayer());
  5080. PacketStruct* packet = configReader.getStruct("WS_UpdateLoot", GetVersion());
  5081. if (packet) {
  5082. entity->AddSpawnLootWindowCompleted(GetPlayer()->GetID(), false);
  5083. vector<Item*>::iterator itr;
  5084. int32 packet_size = 0;
  5085. EQ2Packet* outapp = 0;
  5086. uchar* data = 0;
  5087. vector<Item*> send_items;
  5088. if (items && items->size() > 0) {
  5089. for (int i = 0; i < items->size(); i++) {
  5090. Item* item = (*items)[i];
  5091. if (entity->GetLootMethod() > GroupLootMethod::METHOD_FFA && !ignore_loot_tier) {
  5092. bool skipItem = entity->IsItemInLootTier(item);
  5093. if (!skipItem) {
  5094. send_items.push_back(item);
  5095. }
  5096. }
  5097. else {
  5098. send_items.push_back(item);
  5099. }
  5100. }
  5101. }
  5102. if (GetVersion() >= 374) {
  5103. if (GetVersion() > 561) {
  5104. if (send_items.size() > 0) {
  5105. packet->setDataByName("loot_count", send_items.size());
  5106. packet->setDataByName("display", 1);
  5107. }
  5108. packet->setDataByName("loot_type", entity->GetLootMethod());
  5109. packet->setDataByName("lotto_timeout", entity->GetLootTimeRemaining() / 1000);
  5110. packet->setDataByName("loot_id", entity->GetID());
  5111. EQ2Packet* tmpPacket = packet->serialize();
  5112. packet_size += tmpPacket->size;
  5113. if (send_items.size() > 0) {
  5114. data = new uchar[send_items.size() * 1000 + packet_size];
  5115. memset(data, 0, send_items.size() * 1000 + packet_size);
  5116. }
  5117. else {
  5118. data = new uchar[packet_size];
  5119. memset(data, 0, packet_size);
  5120. }
  5121. uchar* ptr = data;
  5122. memcpy(ptr, tmpPacket->pBuffer, tmpPacket->size);
  5123. ptr += tmpPacket->size;
  5124. safe_delete(tmpPacket);
  5125. Item* item = 0;
  5126. if (send_items.size() > 0) {
  5127. for (itr = send_items.begin(); itr != send_items.end(); itr++) {
  5128. item = *itr;
  5129. memcpy(ptr, &item->details.item_id, sizeof(int32));
  5130. ptr += sizeof(int32);
  5131. packet_size += sizeof(int32);
  5132. tmpPacket = item->serialize(GetVersion(), true, GetPlayer(), false, 1, 0, false, true);
  5133. int8 offset = 0;
  5134. if (GetVersion() >= 1188) {
  5135. offset = 13;
  5136. }
  5137. else if (GetVersion() >= 860) {
  5138. offset = 11;
  5139. }
  5140. else if (GetVersion() <= 561) {
  5141. offset = 19;
  5142. }
  5143. else {
  5144. offset = 10;
  5145. }
  5146. memcpy(ptr, tmpPacket->pBuffer + offset, tmpPacket->size - offset);
  5147. ptr += tmpPacket->size - offset;
  5148. packet_size += tmpPacket->size - offset;
  5149. safe_delete(tmpPacket);
  5150. }
  5151. }
  5152. packet_size -= sizeof(int32);
  5153. memcpy(data, &packet_size, sizeof(int32));
  5154. packet_size += sizeof(int32);
  5155. outapp = new EQ2Packet(OP_ClientCmdMsg, data, packet_size);
  5156. }
  5157. else {
  5158. if (send_items.size() > 0) {
  5159. packet->setArrayLengthByName("loot_count", send_items.size());
  5160. Item* item = 0;
  5161. if (send_items.size() > 0) {
  5162. int i = 0;
  5163. for (itr = send_items.begin(); itr != send_items.end(); itr++) {
  5164. item = *itr;
  5165. packet->setArrayDataByName("loot_id", item->details.item_id, i);
  5166. packet->setItemArrayDataByName("item", item, GetPlayer(), i, 0, 2, true);
  5167. i++;
  5168. }
  5169. }
  5170. packet->setDataByName("display", 1);
  5171. }
  5172. packet->setDataByName("loot_type", entity->GetLootMethod()); // normal
  5173. packet->setDataByName("lotto_timeout", entity->GetLootTimeRemaining() / 1000); // 60 seconds
  5174. packet->setDataByName("spawn_id", entity->GetID());
  5175. outapp = packet->serialize();
  5176. }
  5177. }
  5178. else {
  5179. if (send_items.size() > 0) {
  5180. packet->setArrayLengthByName("loot_count", send_items.size());
  5181. for (int i = 0; i < send_items.size(); i++) {
  5182. Item* item = (send_items)[i];
  5183. packet->setArrayDataByName("name", item->name.c_str(), i);
  5184. packet->setArrayDataByName("item_id", item->details.item_id, i);
  5185. packet->setArrayDataByName("count", item->details.count, i);
  5186. packet->setArrayDataByName("icon", item->details.icon, i);
  5187. if (item->generic_info.skill_req1 > 0 && item->generic_info.skill_req1 < 0xFFFFFFFF)
  5188. packet->setArrayDataByName("ability_id", item->generic_info.skill_req1, i);
  5189. else if (item->generic_info.skill_req2 > 0 && item->generic_info.skill_req2 < 0xFFFFFFFF)
  5190. packet->setArrayDataByName("ability_id", item->generic_info.skill_req2, i);
  5191. else
  5192. packet->setArrayDataByName("ability_id", 0xFFFFFFFF, i);
  5193. }
  5194. }
  5195. packet->setDataByName("display", 1);
  5196. packet->setDataByName("loot_type", entity->GetLootMethod()); // normal
  5197. packet->setDataByName("lotto_timeout", entity->GetLootTimeRemaining() / 1000); // 60 seconds
  5198. packet->setDataByName("object_id", entity->GetID());
  5199. outapp = packet->serialize();
  5200. }
  5201. if (outapp) {
  5202. QueuePacket(outapp);
  5203. }
  5204. safe_delete_array(data);
  5205. safe_delete(packet);
  5206. if (!items || items->size() == 0)
  5207. CloseLoot(entity->GetID());
  5208. }
  5209. }
  5210. bool Client::LootSpawnByMethod(Spawn* entity) {
  5211. bool sentLoot = false;
  5212. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  5213. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  5214. if (gmi && gmi->group_id)
  5215. {
  5216. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  5217. if (group)
  5218. {
  5219. int8 auto_split_coin = group->GetGroupOptions()->auto_split;
  5220. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  5221. deque<GroupMemberInfo*>* members = group->GetMembers();
  5222. int32 split_coin_per_player = 0;
  5223. int32 coins_remain_after_split = entity->GetLootCoins();
  5224. int32 total_coins = entity->GetLootCoins();
  5225. if (auto_split_coin) {
  5226. int8 members_in_zone = 0;
  5227. for (int8 i = 0; i < members->size(); i++) {
  5228. Entity* member = members->at(i)->member;
  5229. if (!member || !member->IsPlayer())
  5230. continue;
  5231. if (member->GetZone() != GetPlayer()->GetZone())
  5232. continue;
  5233. members_in_zone++;
  5234. }
  5235. if (members_in_zone < 1) // this should not happen, but divide by zero checked
  5236. members_in_zone = 0;
  5237. split_coin_per_player = entity->GetLootCoins() / members_in_zone;
  5238. coins_remain_after_split = entity->GetLootCoins() - (split_coin_per_player * members_in_zone);
  5239. entity->SetLootCoins(0, false);
  5240. }
  5241. 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);
  5242. bool startWithLooter = true;
  5243. for (int8 i = 0; i < members->size(); i++) {
  5244. Entity* member = members->at(i)->member;
  5245. if (!member || !member->IsPlayer())
  5246. continue;
  5247. if (member->GetZone() != GetPlayer()->GetZone())
  5248. continue;
  5249. // this will make sure we properly send the loot window to the initial requester if there is no item rarity matches
  5250. if (startWithLooter && member != GetPlayer())
  5251. continue;
  5252. else if (!startWithLooter && member == GetPlayer())
  5253. continue;
  5254. else if (startWithLooter) {
  5255. i = 0;
  5256. startWithLooter = false;
  5257. }
  5258. if (auto_split_coin && (split_coin_per_player + coins_remain_after_split) > 0) {
  5259. player->AddCoins(split_coin_per_player + coins_remain_after_split);
  5260. if (((Player*)member)->GetClient()) {
  5261. ((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());
  5262. }
  5263. if (coins_remain_after_split > 0) // overflow of coin division went to the first player
  5264. coins_remain_after_split = 0;
  5265. }
  5266. switch (entity->GetLootMethod()) {
  5267. case GroupLootMethod::METHOD_LOTTO:
  5268. case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
  5269. if (((Player*)member)->GetClient()) {
  5270. switch (member->GetInfoStruct()->get_group_auto_loot_method()) {
  5271. case 1: { // lotto, need
  5272. if (entity->GetLootMethod() == GroupLootMethod::METHOD_LOTTO) {
  5273. entity->AddLottoItemRequest(0xFFFFFFFF, GetPlayer()->GetID());
  5274. }
  5275. else { // *need* before greed
  5276. entity->AddNeedGreedItemRequest(0xFFFFFFFF, GetPlayer()->GetID(), true);
  5277. }
  5278. entity->AddSpawnLootWindowCompleted(member->GetID(), true);
  5279. // if it already exists we have to override the setting
  5280. entity->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
  5281. break;
  5282. }
  5283. case 2: { // decline
  5284. entity->AddSpawnLootWindowCompleted(member->GetID(), true);
  5285. // if it already exists we have to override the setting
  5286. entity->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
  5287. break;
  5288. }
  5289. default: { // presume 0 or higher than 2
  5290. ((Player*)member)->GetClient()->SendLootResponsePacket((!auto_split_coin && member == GetPlayer()) ? entity->GetLootCoins() : 0, entity->GetLootItems(), entity, true);
  5291. break;
  5292. }
  5293. }
  5294. sentLoot = true;
  5295. }
  5296. break;
  5297. }
  5298. case GroupLootMethod::METHOD_ROUND_ROBIN: {
  5299. entity->AddSpawnLootWindowCompleted(member->GetID(), true);
  5300. sentLoot = true;
  5301. break;
  5302. }
  5303. case GroupLootMethod::METHOD_LEADER: {
  5304. if (member->GetGroupMemberInfo()->leader)
  5305. ((Player*)member)->GetClient()->SendLootResponsePacket((!auto_split_coin && member == GetPlayer()) ? entity->GetLootCoins() : 0, entity->GetLootItems(), entity);
  5306. break;
  5307. }
  5308. case GroupLootMethod::METHOD_FFA: {
  5309. if(member == GetPlayer()) {
  5310. ((Player*)member)->GetClient()->SendLootResponsePacket((!auto_split_coin && member == GetPlayer()) ? entity->GetLootCoins() : 0, entity->GetLootItems(), entity);
  5311. }
  5312. break;
  5313. }
  5314. }
  5315. }
  5316. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  5317. }
  5318. }
  5319. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  5320. return sentLoot;
  5321. }
  5322. void Client::LootSpawnRequest(Spawn* entity, bool attemptDisarm) {
  5323. bool lootAllowed = false;
  5324. bool sentLoot = false;
  5325. std::vector<int32> item_list;
  5326. if (entity->IsNPC()) {
  5327. entity->LockLoot();
  5328. lootAllowed = ((NPC*)entity)->Brain()->CheckLootAllowed(GetPlayer());
  5329. entity->UnlockLoot();
  5330. if (lootAllowed) {
  5331. OpenChest(entity, attemptDisarm);
  5332. }
  5333. else {
  5334. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not allowed to loot at this time.");
  5335. return;
  5336. }
  5337. entity->LockLoot();
  5338. if (((NPC*)entity)->Brain()->CheckLootAllowed(GetPlayer())) {
  5339. lootAllowed = true;
  5340. if ((sentLoot = LootSpawnByMethod(entity))) {
  5341. entity->GetLootItemsList(&item_list);
  5342. }
  5343. else {
  5344. SendLootResponsePacket(entity->GetLootCoins(), entity->GetLootItems(), entity);
  5345. }
  5346. }
  5347. entity->UnlockLoot();
  5348. if (lootAllowed) {
  5349. entity->DistributeGroupLoot_RoundRobin(&item_list, true);
  5350. }
  5351. }
  5352. }
  5353. void Client::OpenChest(Spawn* entity, bool attemptDisarm)
  5354. {
  5355. if (!entity)
  5356. return;
  5357. int8 chest_difficulty = 0;
  5358. int32 state = 0;
  5359. // Check for the chest and set the action state
  5360. /*4034 = small chest | 5864 = treasure chest | 5865 = ornate treasure chest | 4015 = exquisite chest*/
  5361. string modelName;
  5362. if (entity->GetModelType() == 4034) {
  5363. // small chest, open with copper coins
  5364. // does not include traps, however can be disarmed
  5365. chest_difficulty = 1;
  5366. state = 11899;
  5367. modelName.append("Small Chest");
  5368. }
  5369. else if (entity->GetModelType() == 5864) {
  5370. // treasure chest, open with silver coins
  5371. chest_difficulty = 2;
  5372. state = 11901;
  5373. modelName.append("Treasure Chest");
  5374. }
  5375. else if (entity->GetModelType() == 5865) {
  5376. // ornate chest, open with gold coins
  5377. chest_difficulty = 3;
  5378. state = 11900;
  5379. modelName.append("Ornate Chest");
  5380. }
  5381. else if (entity->GetModelType() == 4015) {
  5382. // exquisite chest, open with gold coins and jewels as well as a glow effect
  5383. chest_difficulty = 5;
  5384. state = 11898;
  5385. modelName.append("Exquisite Chest");
  5386. }
  5387. bool firstChestOpen = false;
  5388. if (chest_difficulty > 0 && !entity->HasTrapTriggered())
  5389. {
  5390. ChestTrap::ChestTrapInfo nextTrap;
  5391. bool ret = chest_trap_list.GetNextTrap(GetCurrentZone()->GetZoneID(), chest_difficulty, &nextTrap);
  5392. Skill* disarmSkill = GetPlayer()->GetSkillByName("Disarm Trap", false);
  5393. firstChestOpen = true;
  5394. entity->SetTrapTriggered(true, state);
  5395. if (ret)
  5396. {
  5397. if (disarmSkill && attemptDisarm)
  5398. {
  5399. if (disarmSkill->CheckDisarmSkill(entity->GetLevel(), chest_difficulty) < 1)
  5400. {
  5401. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  5402. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  5403. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  5404. }
  5405. else
  5406. {
  5407. Message(CHANNEL_NARRATIVE, "You disarm the trap on %s", modelName.c_str());
  5408. }
  5409. // despite fail/succeed we should always try to increase skill if disarm is available
  5410. GetPlayer()->GetSkillByName("Disarm Trap", true);
  5411. }
  5412. else // no disarm skill, always fail
  5413. {
  5414. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  5415. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  5416. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  5417. }
  5418. }
  5419. }
  5420. else if (!entity->HasTrapTriggered())
  5421. {
  5422. firstChestOpen = true;
  5423. entity->SetTrapTriggered(true, state);
  5424. }
  5425. // We set the visual state with out updating so those not in range will see it opened when it is finally sent to them,
  5426. // for those in range the SendStateCommand will cause it to animate open.
  5427. // players not currently in radius will have it queued with client->QueueStateCommand when SendSpawn takes place
  5428. if (firstChestOpen)
  5429. GetCurrentZone()->SendStateCommand(entity, state);
  5430. }
  5431. void Client::CastGroupOrSelf(Entity* source, uint32 spellID, uint32 spellTier, float restrictiveRadius)
  5432. {
  5433. Spell* spell = master_spell_list.GetSpell(spellID, spellTier);
  5434. SpellProcess* spellProcess = GetCurrentZone()->GetSpellProcess();
  5435. if (source == NULL)
  5436. source = (Entity*)GetPlayer();
  5437. if (spell)
  5438. {
  5439. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  5440. if (gmi && gmi->group_id)
  5441. {
  5442. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  5443. if (group)
  5444. {
  5445. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  5446. deque<GroupMemberInfo*>* members = group->GetMembers();
  5447. for (int8 i = 0; i < members->size(); i++) {
  5448. Entity* member = members->at(i)->member;
  5449. if(!member)
  5450. continue;
  5451. if (!member->Alive() || (member->GetZone() != source->GetZone()))
  5452. continue;
  5453. // if we have a radius provided then check if the group member is outside the radius or not
  5454. if (restrictiveRadius > 0.0f && member->GetDistance(source) > restrictiveRadius)
  5455. continue;
  5456. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  5457. }
  5458. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  5459. }
  5460. }
  5461. else
  5462. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  5463. }
  5464. }
  5465. Spawn* Client::GetBanker() {
  5466. return banker;
  5467. }
  5468. void Client::SetBanker(Spawn* in_banker) {
  5469. banker = in_banker;
  5470. }
  5471. void Client::Bank(Spawn* banker, bool cancel) {
  5472. if (banker && banker->primary_command_list.size() > 0 && banker->primary_command_list[0]->command == "bank") {
  5473. if (!cancel)
  5474. SetBanker(banker);
  5475. else
  5476. SetBanker(0);
  5477. PacketStruct* packet = configReader.getStruct("WS_UpdateBank", GetVersion());
  5478. if (packet) {
  5479. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(banker));
  5480. int64 coins = GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + GetPlayer()->GetInfoStruct()->get_bank_coin_silver() * 100 +
  5481. GetPlayer()->GetInfoStruct()->get_bank_coin_gold() * 10000 + (int64)GetPlayer()->GetInfoStruct()->get_bank_coin_plat() * 1000000;
  5482. int32 coins1, coins2;
  5483. coins1 = ((int32*)&coins)[0];
  5484. coins2 = ((int32*)&coins)[1];
  5485. packet->setDataByName("bank_coins", coins1);
  5486. packet->setDataByName("bank_coins2", coins2);
  5487. packet->setDataByName("copper", GetPlayer()->GetInfoStruct()->get_coin_copper());
  5488. packet->setDataByName("silver", GetPlayer()->GetInfoStruct()->get_coin_silver());
  5489. packet->setDataByName("gold", GetPlayer()->GetInfoStruct()->get_coin_gold());
  5490. packet->setDataByName("plat", GetPlayer()->GetInfoStruct()->get_coin_plat());
  5491. if (!cancel)
  5492. packet->setDataByName("display", 1);
  5493. QueuePacket(packet->serialize());
  5494. safe_delete(packet);
  5495. }
  5496. }
  5497. }
  5498. bool Client::BankHasCoin(int64 amount){
  5499. int32 tmp = 0;
  5500. if(amount <= 0)
  5501. return 0;
  5502. //plat
  5503. if (amount >= 1000000) {
  5504. tmp = amount / 1000000;
  5505. int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
  5506. if(bank_coins_plat >= tmp)
  5507. return 1;
  5508. }
  5509. //gold
  5510. if (amount >= 10000) {
  5511. tmp = amount / 10000;
  5512. int32 bank_coins_gold = GetPlayer()->GetBankCoinsGold();
  5513. if(bank_coins_gold >= tmp)
  5514. return 1;
  5515. }
  5516. //silver
  5517. if (amount >= 100) {
  5518. tmp = amount / 100;
  5519. int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
  5520. if(bank_coins_silver >= tmp)
  5521. return 1;
  5522. }
  5523. //copper
  5524. if (amount > 0) {
  5525. int32 bank_coins_copper = GetPlayer()->GetBankCoinsCopper();
  5526. if(bank_coins_copper >= amount)
  5527. return 1;
  5528. }
  5529. return 0;
  5530. }
  5531. bool Client::BankWithdrawalNoBanker(int64 amount) {
  5532. bool cheater = false;
  5533. if (amount > 0) {
  5534. string withdrawal = "";
  5535. char withdrawal_data[512] = { 0 };
  5536. int32 tmp = 0;
  5537. if (amount >= 1000000) {
  5538. tmp = amount / 1000000;
  5539. int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
  5540. if (tmp > bank_coins_plat)
  5541. cheater = true;
  5542. else {
  5543. GetPlayer()->GetInfoStruct()->set_bank_coin_plat(bank_coins_plat - tmp);
  5544. GetPlayer()->GetInfoStruct()->add_coin_plat(tmp);
  5545. amount -= (int64)tmp * 1000000;
  5546. sprintf(withdrawal_data, "%u Platinum ", tmp);
  5547. withdrawal.append(withdrawal_data);
  5548. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5549. }
  5550. }
  5551. if (!cheater && amount >= 10000) {
  5552. tmp = amount / 10000;
  5553. if (tmp > GetPlayer()->GetBankCoinsGold())
  5554. cheater = true;
  5555. else {
  5556. int32 bank_coins_gold = GetPlayer()->GetInfoStruct()->get_bank_coin_gold();
  5557. bank_coins_gold -= tmp;
  5558. if ((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) > 100) {
  5559. GetPlayer()->GetInfoStruct()->set_coin_gold((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) - 100);
  5560. GetPlayer()->GetInfoStruct()->add_coin_plat(1);
  5561. }
  5562. else
  5563. GetPlayer()->GetInfoStruct()->add_coin_gold(tmp);
  5564. amount -= tmp * 10000;
  5565. sprintf(withdrawal_data, "%u Gold ", tmp);
  5566. withdrawal.append(withdrawal_data);
  5567. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5568. }
  5569. }
  5570. if (!cheater && amount >= 100) {
  5571. tmp = amount / 100;
  5572. int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
  5573. if (tmp > bank_coins_silver)
  5574. cheater = true;
  5575. else {
  5576. GetPlayer()->GetInfoStruct()->set_bank_coin_silver(bank_coins_silver - tmp);
  5577. if ((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) > 100) {
  5578. GetPlayer()->GetInfoStruct()->set_coin_silver((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) - 100);
  5579. GetPlayer()->GetInfoStruct()->add_coin_gold(1);
  5580. }
  5581. else
  5582. GetPlayer()->GetInfoStruct()->add_coin_silver(tmp);
  5583. amount -= tmp * 100;
  5584. sprintf(withdrawal_data, "%u Silver ", tmp);
  5585. withdrawal.append(withdrawal_data);
  5586. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5587. }
  5588. }
  5589. if (!cheater) {
  5590. if (amount > 0) {
  5591. sprintf(withdrawal_data, "%u Copper ", (int32)amount);
  5592. withdrawal.append(withdrawal_data);
  5593. int32 bank_coin_copper = GetPlayer()->GetInfoStruct()->get_bank_coin_copper();
  5594. GetPlayer()->GetInfoStruct()->set_bank_coin_copper(bank_coin_copper - amount);
  5595. if ((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) > 100) {
  5596. GetPlayer()->GetInfoStruct()->set_coin_copper((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) - 100);
  5597. GetPlayer()->GetInfoStruct()->add_coin_silver(1);
  5598. }
  5599. else
  5600. GetPlayer()->GetInfoStruct()->add_coin_copper(amount);
  5601. }
  5602. if (withdrawal.length() > 0) {
  5603. withdrawal.append("withdrawn ");
  5604. sprintf(withdrawal_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  5605. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  5606. withdrawal.append(withdrawal_data);
  5607. SimpleMessage(CHANNEL_NARRATIVE, withdrawal.c_str());
  5608. return 1;
  5609. }
  5610. }
  5611. else
  5612. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  5613. return 0;
  5614. }
  5615. return 0;
  5616. }
  5617. void Client::BankWithdrawal(int64 amount) {
  5618. bool cheater = false;
  5619. if (GetBanker() && amount > 0) {
  5620. string withdrawal = "";
  5621. char withdrawal_data[512] = { 0 };
  5622. int32 tmp = 0;
  5623. if (amount >= 1000000) {
  5624. tmp = amount / 1000000;
  5625. int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
  5626. if (tmp > bank_coins_plat)
  5627. cheater = true;
  5628. else {
  5629. GetPlayer()->GetInfoStruct()->set_bank_coin_plat(bank_coins_plat - tmp);
  5630. GetPlayer()->GetInfoStruct()->add_coin_plat(tmp);
  5631. amount -= (int64)tmp * 1000000;
  5632. sprintf(withdrawal_data, "%u Platinum ", tmp);
  5633. withdrawal.append(withdrawal_data);
  5634. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5635. }
  5636. }
  5637. if (!cheater && amount >= 10000) {
  5638. tmp = amount / 10000;
  5639. if (tmp > GetPlayer()->GetBankCoinsGold())
  5640. cheater = true;
  5641. else {
  5642. int32 bank_coins_gold = GetPlayer()->GetInfoStruct()->get_bank_coin_gold();
  5643. bank_coins_gold -= tmp;
  5644. if ((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) > 100) {
  5645. GetPlayer()->GetInfoStruct()->set_coin_gold((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) - 100);
  5646. GetPlayer()->GetInfoStruct()->add_coin_plat(1);
  5647. }
  5648. else
  5649. GetPlayer()->GetInfoStruct()->add_coin_gold(tmp);
  5650. amount -= tmp * 10000;
  5651. sprintf(withdrawal_data, "%u Gold ", tmp);
  5652. withdrawal.append(withdrawal_data);
  5653. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5654. }
  5655. }
  5656. if (!cheater && amount >= 100) {
  5657. tmp = amount / 100;
  5658. int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
  5659. if (tmp > bank_coins_silver)
  5660. cheater = true;
  5661. else {
  5662. GetPlayer()->GetInfoStruct()->set_bank_coin_silver(bank_coins_silver - tmp);
  5663. if ((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) > 100) {
  5664. GetPlayer()->GetInfoStruct()->set_coin_silver((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) - 100);
  5665. GetPlayer()->GetInfoStruct()->add_coin_gold(1);
  5666. }
  5667. else
  5668. GetPlayer()->GetInfoStruct()->add_coin_silver(tmp);
  5669. amount -= tmp * 100;
  5670. sprintf(withdrawal_data, "%u Silver ", tmp);
  5671. withdrawal.append(withdrawal_data);
  5672. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5673. }
  5674. }
  5675. if (!cheater) {
  5676. if (amount > 0) {
  5677. sprintf(withdrawal_data, "%u Copper ", (int32)amount);
  5678. withdrawal.append(withdrawal_data);
  5679. int32 bank_coin_copper = GetPlayer()->GetInfoStruct()->get_bank_coin_copper();
  5680. GetPlayer()->GetInfoStruct()->set_bank_coin_copper(bank_coin_copper - amount);
  5681. if ((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) > 100) {
  5682. GetPlayer()->GetInfoStruct()->set_coin_copper((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) - 100);
  5683. GetPlayer()->GetInfoStruct()->add_coin_silver(1);
  5684. }
  5685. else
  5686. GetPlayer()->GetInfoStruct()->add_coin_copper(amount);
  5687. }
  5688. if (withdrawal.length() > 0) {
  5689. withdrawal.append("withdrawn ");
  5690. sprintf(withdrawal_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  5691. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  5692. withdrawal.append(withdrawal_data);
  5693. SimpleMessage(CHANNEL_NARRATIVE, withdrawal.c_str());
  5694. }
  5695. }
  5696. else
  5697. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  5698. player->SetCharSheetChanged(true);
  5699. Bank(banker);
  5700. }
  5701. }
  5702. void Client::BankDeposit(int64 amount) {
  5703. bool cheater = false;
  5704. if (GetBanker() && amount > 0) {
  5705. int32 tmp = 0;
  5706. char deposit_data[512] = { 0 };
  5707. string deposit = "";
  5708. if (amount >= 1000000) {
  5709. tmp = amount / 1000000;
  5710. if (tmp > GetPlayer()->GetCoinsPlat())
  5711. cheater = true;
  5712. else {
  5713. GetPlayer()->GetInfoStruct()->add_bank_coin_plat(tmp);
  5714. GetPlayer()->GetInfoStruct()->set_coin_plat(GetPlayer()->GetInfoStruct()->get_coin_plat() - tmp);
  5715. amount -= (int64)tmp * 1000000;
  5716. sprintf(deposit_data, "%u Platinum ", tmp);
  5717. deposit.append(deposit_data);
  5718. memset(deposit_data, 0, sizeof(deposit_data));
  5719. }
  5720. }
  5721. if (!cheater && amount >= 10000) {
  5722. tmp = amount / 10000;
  5723. if (tmp > GetPlayer()->GetCoinsGold())
  5724. cheater = true;
  5725. else {
  5726. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_gold() + tmp) > 100) {
  5727. GetPlayer()->GetInfoStruct()->set_bank_coin_gold((GetPlayer()->GetInfoStruct()->get_bank_coin_gold() + tmp) - 100);
  5728. GetPlayer()->GetInfoStruct()->add_bank_coin_plat(1);
  5729. }
  5730. else
  5731. GetPlayer()->GetInfoStruct()->add_bank_coin_gold(tmp);
  5732. GetPlayer()->GetInfoStruct()->set_coin_gold(GetPlayer()->GetInfoStruct()->get_coin_gold() - tmp);
  5733. amount -= tmp * 10000;
  5734. sprintf(deposit_data, "%u Gold ", tmp);
  5735. deposit.append(deposit_data);
  5736. memset(deposit_data, 0, sizeof(deposit_data));
  5737. }
  5738. }
  5739. if (!cheater && amount >= 100) {
  5740. tmp = amount / 100;
  5741. if (tmp > GetPlayer()->GetCoinsSilver())
  5742. cheater = true;
  5743. else {
  5744. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_silver() + tmp) > 100) {
  5745. GetPlayer()->GetInfoStruct()->set_bank_coin_silver((GetPlayer()->GetInfoStruct()->get_bank_coin_silver() + tmp) - 100);
  5746. GetPlayer()->GetInfoStruct()->add_bank_coin_gold(1);
  5747. }
  5748. else
  5749. GetPlayer()->GetInfoStruct()->add_bank_coin_silver(tmp);
  5750. GetPlayer()->GetInfoStruct()->set_coin_silver(GetPlayer()->GetInfoStruct()->get_coin_silver() - tmp);
  5751. amount -= tmp * 100;
  5752. sprintf(deposit_data, "%u Silver ", tmp);
  5753. deposit.append(deposit_data);
  5754. memset(deposit_data, 0, sizeof(deposit_data));
  5755. }
  5756. }
  5757. if (!cheater) {
  5758. if (amount > 0) {
  5759. sprintf(deposit_data, "%u Copper ", (int32)amount);
  5760. deposit.append(deposit_data);
  5761. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + amount) > 100) {
  5762. GetPlayer()->GetInfoStruct()->set_bank_coin_copper((GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + amount) - 100);
  5763. GetPlayer()->GetInfoStruct()->add_bank_coin_silver(1);
  5764. }
  5765. else
  5766. GetPlayer()->GetInfoStruct()->add_bank_coin_copper(amount);
  5767. GetPlayer()->GetInfoStruct()->set_coin_copper(GetPlayer()->GetInfoStruct()->get_coin_copper() - amount);
  5768. }
  5769. if (deposit.length() > 0) {
  5770. deposit.append("deposited ");
  5771. sprintf(deposit_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  5772. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  5773. deposit.append(deposit_data);
  5774. SimpleMessage(CHANNEL_NARRATIVE, deposit.c_str());
  5775. }
  5776. }
  5777. else
  5778. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  5779. player->SetCharSheetChanged(true);
  5780. Bank(banker);
  5781. }
  5782. }
  5783. void Client::AddPendingQuestAcceptReward(Quest* quest)
  5784. {
  5785. std::unique_lock lock(MPendingQuestAccept);
  5786. pending_quest_accept.push_back(quest->GetQuestID());
  5787. }
  5788. void Client::AddPendingQuestReward(Quest* quest, bool update, bool is_temporary, std::string description) {
  5789. QueueQuestReward(quest->GetQuestID(), is_temporary, false, false, (is_temporary ? quest->GetCoinTmpReward() : 0),
  5790. (is_temporary ? quest->GetStatusTmpReward() : 0), description, false, 0);
  5791. quest_updates = update;
  5792. if(quest_updates) {
  5793. SaveQuestRewardData(true);
  5794. }
  5795. }
  5796. 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) {
  5797. if(HasQuestRewardQueued(quest_id, is_temporary, is_collection))
  5798. return;
  5799. QuestRewardData* data = new QuestRewardData;
  5800. data->quest_id = quest_id;
  5801. data->is_temporary = is_temporary;
  5802. data->is_collection = is_collection;
  5803. data->has_displayed = has_displayed;
  5804. data->tmp_coin = tmp_coin;
  5805. data->tmp_status = tmp_status;
  5806. data->description = std::string(description);
  5807. data->db_saved = db_saved;
  5808. data->db_index = index;
  5809. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5810. quest_pending_reward.push_back(data);
  5811. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5812. }
  5813. bool Client::HasQuestRewardQueued(int32 quest_id, bool is_temporary, bool is_collection) {
  5814. bool success = false;
  5815. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  5816. if (quest_pending_reward.size() > 0) {
  5817. vector<QuestRewardData*>::iterator itr;
  5818. for (itr = quest_pending_reward.begin(); itr != quest_pending_reward.end(); itr++) {
  5819. int32 questID = (*itr)->quest_id;
  5820. bool temporary = (*itr)->is_temporary;
  5821. bool collection = (*itr)->is_collection;
  5822. if( questID == quest_id && is_temporary == temporary && is_collection == collection ) {
  5823. success = true;
  5824. break;
  5825. }
  5826. }
  5827. }
  5828. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5829. return success;
  5830. }
  5831. void Client::RemoveQueuedQuestReward() {
  5832. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5833. if(quest_pending_reward.size() > 0) {
  5834. QuestRewardData* data = quest_pending_reward.at(0);
  5835. if(data->db_saved) {
  5836. Query query;
  5837. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete FROM character_quest_rewards where char_id = %u and indexed = %u", GetCharacterID(), data->db_index);
  5838. if(data->is_temporary && data->quest_id) {
  5839. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete FROM character_quest_temporary_rewards where char_id = %u and quest_id = %u", GetCharacterID(), data->quest_id);
  5840. }
  5841. }
  5842. quest_pending_reward.erase(quest_pending_reward.begin());
  5843. }
  5844. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5845. SaveQuestRewardData(true);
  5846. }
  5847. void Client::AddPendingQuestUpdate(int32 quest_id, int32 step_id, int32 progress) {
  5848. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5849. quest_pending_updates[quest_id][step_id] = progress;
  5850. quest_updates = true;
  5851. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5852. }
  5853. void Client::ProcessQuestUpdates() {
  5854. if(!IsReadyForUpdates())
  5855. return;
  5856. if (quest_pending_updates.size() > 0) {
  5857. map<int32, map<int32, int32> > tmp_quest_updates;
  5858. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5859. tmp_quest_updates.insert(quest_pending_updates.begin(), quest_pending_updates.end());
  5860. quest_pending_updates.clear();
  5861. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5862. map<int32, map<int32, int32> >::iterator quest_itr;
  5863. map<int32, int32>::iterator step_itr;
  5864. for (quest_itr = tmp_quest_updates.begin(); quest_itr != tmp_quest_updates.end(); quest_itr++) {
  5865. for (step_itr = quest_itr->second.begin(); step_itr != quest_itr->second.end(); step_itr++) {
  5866. if (step_itr->second == 0xFFFFFFFF) {
  5867. SetStepComplete(quest_itr->first, step_itr->first);
  5868. player->SendQuestRequiredSpawns(quest_itr->first);
  5869. }
  5870. else
  5871. AddStepProgress(quest_itr->first, step_itr->first, step_itr->second);
  5872. }
  5873. }
  5874. }
  5875. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  5876. if (quest_pending_reward.size() > 0) {
  5877. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5878. // only able to display one reward at a time
  5879. if(GetPlayer()->IsActiveReward())
  5880. return;
  5881. Query query;
  5882. vector<QuestRewardData*>::iterator itr;
  5883. vector<QuestRewardData*> tmp_quest_rewards;
  5884. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5885. tmp_quest_rewards.insert(tmp_quest_rewards.begin(), quest_pending_reward.begin(), quest_pending_reward.begin()+1);
  5886. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5887. bool delete_first = false;
  5888. for (itr = tmp_quest_rewards.begin(); itr != tmp_quest_rewards.end();) {
  5889. int32 questID = (*itr)->quest_id;
  5890. if((*itr)->is_collection && GetPlayer()->GetPendingCollectionReward()) {
  5891. DisplayCollectionComplete(GetPlayer()->GetPendingCollectionReward());
  5892. GetPlayer()->SetActiveReward(true);
  5893. (*itr)->has_displayed = true;
  5894. UpdateCharacterRewardData((*itr));
  5895. break;
  5896. }
  5897. else if(questID > 0 && GetPlayer()->UpdateQuestReward(questID, (*itr))) {
  5898. (*itr)->has_displayed = true;
  5899. UpdateCharacterRewardData((*itr));
  5900. // only able to display one reward at a time
  5901. break;
  5902. } else {
  5903. delete_first = true;
  5904. LogWrite(CCLIENT__ERROR, 0, "Client", "Quest ID %u missing for Player %s, deleting quest id from tmp_quest_rewards.", questID, GetPlayer()->GetName());
  5905. break;
  5906. }
  5907. }
  5908. if(delete_first) {
  5909. RemoveQueuedQuestReward();
  5910. }
  5911. } else {
  5912. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5913. }
  5914. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  5915. if (quest_pending_reward.size() > 0) {
  5916. quest_updates = true;
  5917. }
  5918. else {
  5919. quest_updates = false;
  5920. }
  5921. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5922. }
  5923. void Client::CheckQuestQueue() {
  5924. MQuestQueue.writelock();
  5925. last_update_time = 0;
  5926. vector<QueuedQuest*>::iterator itr;
  5927. for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
  5928. if(!GetPlayer()->SendQuestStepUpdate((*itr)->quest_id, (*itr)->step, (*itr)->display_quest_helper)) {
  5929. LogWrite(CCLIENT__ERROR, 0, "Client", "Queued Quest ID %u missing for Player %s, cannot send quest step update.", (*itr)->quest_id, GetPlayer()->GetName());
  5930. }
  5931. safe_delete((*itr));
  5932. }
  5933. quest_queue.clear();
  5934. MQuestQueue.releasewritelock();
  5935. }
  5936. void Client::SetStepComplete(int32 quest_id, int32 step) {
  5937. Quest* quest = player->SetStepComplete(quest_id, step);
  5938. if (quest) {
  5939. SendQuestUpdate(quest);
  5940. GetCurrentZone()->SendQuestUpdates(this);
  5941. }
  5942. }
  5943. void Client::AddStepProgress(int32 quest_id, int32 step, int32 progress) {
  5944. Quest* quest = player->AddStepProgress(quest_id, step, progress);
  5945. if (quest) {
  5946. SendQuestUpdate(quest);
  5947. GetCurrentZone()->SendQuestUpdates(this);
  5948. }
  5949. }
  5950. void Client::CheckPlayerQuestsKillUpdate(Spawn* spawn) {
  5951. bool hadUpdates = false;
  5952. vector<Quest*>* quest_updates = player->CheckQuestsKillUpdate(spawn);
  5953. if (quest_updates) {
  5954. for (int32 i = 0; i < quest_updates->size(); i++)
  5955. {
  5956. SendQuestUpdate(quest_updates->at(i));
  5957. hadUpdates = true;
  5958. }
  5959. }
  5960. safe_delete(quest_updates);
  5961. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  5962. if (quest_failures) {
  5963. for (int32 i = 0; i < quest_failures->size(); i++)
  5964. {
  5965. SendQuestFailure(quest_failures->at(i));
  5966. hadUpdates = true;
  5967. }
  5968. }
  5969. safe_delete(quest_failures);
  5970. if (hadUpdates)
  5971. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  5972. }
  5973. void Client::CheckPlayerQuestsChatUpdate(Spawn* spawn) {
  5974. vector<Quest*>* quest_updates = player->CheckQuestsChatUpdate(spawn);
  5975. if (quest_updates) {
  5976. for (int32 i = 0; i < quest_updates->size(); i++)
  5977. SendQuestUpdate(quest_updates->at(i));
  5978. GetCurrentZone()->SendQuestUpdates(this);
  5979. }
  5980. safe_delete(quest_updates);
  5981. }
  5982. void Client::CheckPlayerQuestsItemUpdate(Item* item) {
  5983. vector<Quest*>* quest_updates = player->CheckQuestsItemUpdate(item);
  5984. if (quest_updates) {
  5985. for (int32 i = 0; i < quest_updates->size(); i++)
  5986. SendQuestUpdate(quest_updates->at(i));
  5987. }
  5988. safe_delete(quest_updates);
  5989. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  5990. if (quest_failures) {
  5991. for (int32 i = 0; i < quest_failures->size(); i++)
  5992. SendQuestFailure(quest_failures->at(i));
  5993. }
  5994. safe_delete(quest_failures);
  5995. }
  5996. void Client::CheckPlayerQuestsLocationUpdate() {
  5997. vector<Quest*>* quest_updates = player->CheckQuestsLocationUpdate();
  5998. if (quest_updates) {
  5999. for (int32 i = 0; i < quest_updates->size(); i++)
  6000. SendQuestUpdate(quest_updates->at(i));
  6001. }
  6002. safe_delete(quest_updates);
  6003. }
  6004. void Client::CheckPlayerQuestsSpellUpdate(Spell* spell) {
  6005. vector<Quest*>* quest_updates = player->CheckQuestsSpellUpdate(spell);
  6006. if (quest_updates) {
  6007. for (int32 i = 0; i < quest_updates->size(); i++)
  6008. SendQuestUpdate(quest_updates->at(i));
  6009. }
  6010. safe_delete(quest_updates);
  6011. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  6012. if (quest_failures) {
  6013. for (int32 i = 0; i < quest_failures->size(); i++)
  6014. SendQuestFailure(quest_failures->at(i));
  6015. }
  6016. safe_delete(quest_failures);
  6017. }
  6018. void Client::AddPendingQuest(Quest* quest, bool forced) {
  6019. if (version <= 372 || forced) { //this client doesn't ask if you want the quest, so auto accept
  6020. MPendingQuestAccept.lock();
  6021. player->pending_quests[quest->GetQuestID()] = quest;
  6022. MPendingQuestAccept.unlock();
  6023. AcceptQuest(quest->GetQuestID());
  6024. }
  6025. else {
  6026. MPendingQuestAccept.lock();
  6027. player->pending_quests[quest->GetQuestID()] = quest;
  6028. MPendingQuestAccept.unlock();
  6029. EQ2Packet* outapp = quest->OfferQuest(GetVersion(), player);
  6030. //DumpPacket(outapp);
  6031. QueuePacket(outapp);
  6032. }
  6033. }
  6034. void Client::AcceptQuest(int32 quest_id) {
  6035. MPendingQuestAccept.lock_shared();
  6036. if (player->pending_quests.count(quest_id) > 0) {
  6037. Quest* quest = player->pending_quests[quest_id];
  6038. if(quest) {
  6039. MPendingQuestAccept.unlock_shared();
  6040. MPendingQuestAccept.lock();
  6041. player->pending_quests.erase(quest->GetQuestID());
  6042. MPendingQuestAccept.unlock();
  6043. AddPlayerQuest(quest);
  6044. GetCurrentZone()->SendQuestUpdates(this);
  6045. GetPlayer()->UpdateQuestCompleteCount(quest_id);
  6046. return; // already unlocked mutex
  6047. }
  6048. }
  6049. MPendingQuestAccept.unlock_shared();
  6050. }
  6051. void Client::RemovePendingQuest(int32 quest_id) {
  6052. bool send_updates = false;
  6053. MPendingQuestAccept.lock_shared();
  6054. if (player->pending_quests.count(quest_id) > 0) {
  6055. Quest* quest = player->pending_quests[quest_id];
  6056. MPendingQuestAccept.unlock_shared();
  6057. MPendingQuestAccept.lock();
  6058. player->pending_quests.erase(quest_id);
  6059. MPendingQuestAccept.unlock();
  6060. if(lua_interface) {
  6061. lua_interface->CallQuestFunction(quest, "Declined", GetPlayer());
  6062. lua_interface->SetLuaUserDataStale(quest);
  6063. }
  6064. safe_delete(quest);
  6065. send_updates = true;
  6066. }
  6067. else {
  6068. MPendingQuestAccept.unlock_shared();
  6069. }
  6070. if(send_updates) {
  6071. GetCurrentZone()->SendQuestUpdates(this);
  6072. }
  6073. }
  6074. void Client::SetPlayerQuest(Quest* quest, map<int32, int32>* progress) {
  6075. if (!quest || !progress) {
  6076. return;
  6077. }
  6078. map<int32, int32>::iterator itr;
  6079. QuestStep* step = 0;
  6080. for (itr = progress->begin(); itr != progress->end(); itr++) {
  6081. step = quest->GetQuestStep(itr->first);
  6082. if (step && itr->second > 0) {
  6083. step->SetStepProgress(itr->second);
  6084. if (lua_interface && step->GetQuestCurrentQuantity() >= step->GetQuestNeededQuantity())
  6085. lua_interface->CallQuestFunction(quest, "Reload", player, step->GetStepID());
  6086. }
  6087. }
  6088. if (lua_interface && step)
  6089. lua_interface->CallQuestFunction(quest, "CurrentStep", player, step->GetStepID());
  6090. else if(!step) {
  6091. LogWrite(QUEST__ERROR, 0, "Client", "Missing step for quest %s (ID %u), cannot CallQuestFunction for CurrentStep", quest->GetName(), quest->GetQuestID());
  6092. }
  6093. }
  6094. void Client::AddPlayerQuest(Quest* quest, bool call_accepted, bool send_packets) {
  6095. bool lockCleared = false;
  6096. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  6097. if (player->player_quests.count(quest->GetQuestID()) > 0 && player->player_quests[quest->GetQuestID()]) {
  6098. if (player->player_quests[quest->GetQuestID()]->GetQuestFlags() > 0)
  6099. quest->SetQuestFlags(player->player_quests[quest->GetQuestID()]->GetQuestFlags());
  6100. int32 questID = quest->GetQuestID();
  6101. lockCleared = true;
  6102. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  6103. RemovePlayerQuest(questID, false, false);
  6104. }
  6105. player->player_quests[quest->GetQuestID()] = quest;
  6106. if(!lockCleared)
  6107. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  6108. quest->SetPlayer(player);
  6109. quest->SetSaveNeeded(true);
  6110. current_quest_id = quest->GetQuestID();
  6111. if (send_packets && quest->GetQuestGiver() > 0)
  6112. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  6113. if (lua_interface && call_accepted)
  6114. lua_interface->CallQuestFunction(quest, "Accepted", player);
  6115. if (send_packets) {
  6116. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6117. //SendQuestJournal();
  6118. SendQuestJournalUpdate(quest);
  6119. // sent twice to match live
  6120. quest->SetTracked(false);
  6121. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  6122. quest->SetTracked(true);
  6123. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  6124. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  6125. }
  6126. //This isn't during a load screen, so update spawns with required quests
  6127. if (call_accepted)
  6128. player->SendQuestRequiredSpawns(quest->GetQuestID());
  6129. }
  6130. void Client::RemovePlayerQuest(int32 id, bool send_update, bool delete_quest) {
  6131. if (current_quest_id == id)
  6132. current_quest_id = 0;
  6133. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  6134. if (player->player_quests.count(id) > 0 && player->player_quests[id]) {
  6135. if (delete_quest) {
  6136. player->player_quests[id]->SetDeleted(true);
  6137. database.DeleteCharacterQuest(id, GetCharacterID(), player->GetCompletedPlayerQuests()->count(id) > 0);
  6138. }
  6139. int32 quest_giver = player->player_quests[id]->GetQuestGiver();
  6140. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  6141. if (send_update && quest_giver > 0)
  6142. GetCurrentZone()->SendSpawnChangesByDBID(quest_giver, this, false, true);
  6143. if (send_update) {
  6144. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6145. SendQuestJournal(false, 0, true);
  6146. }
  6147. player->RemoveQuest(id, delete_quest);
  6148. if (send_update) {
  6149. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6150. SendQuestJournal(false, 0, true);
  6151. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  6152. }
  6153. }
  6154. else {
  6155. // if we don't have any quests to count then release the write lock
  6156. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  6157. }
  6158. }
  6159. void Client::SendQuestUpdateStepImmediately(Quest* quest, int32 step, bool display_quest_helper) {
  6160. if (quest) {
  6161. QuestStep* quest_step = quest->GetQuestStep(step);
  6162. if (quest_step) {
  6163. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, quest_step, 1, false, false, display_quest_helper));
  6164. quest_step->WasUpdated(false);
  6165. }
  6166. }
  6167. }
  6168. void Client::SendQuestUpdateStep(Quest* quest, int32 step, bool display_quest_helper) {
  6169. QueuedQuest* item = new QueuedQuest;
  6170. item->quest_id = quest->GetQuestID();
  6171. item->step = step;
  6172. item->display_quest_helper = display_quest_helper;
  6173. MQuestQueue.writelock();
  6174. quest_queue.push_back(item);
  6175. last_update_time = Timer::GetCurrentTime2();
  6176. MQuestQueue.releasewritelock();
  6177. }
  6178. void Client::SendQuestFailure(Quest* quest) {
  6179. vector<QuestStep*>* failures = quest->GetQuestFailures();
  6180. if (failures) {
  6181. QuestStep* step = 0;
  6182. for (int32 i = 0; i < failures->size(); i++) {
  6183. step = failures->at(i);
  6184. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step, 1, false, true));
  6185. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6186. SendQuestJournal(false, 0, true);
  6187. }
  6188. failures->clear();
  6189. }
  6190. }
  6191. void Client::SendQuestUpdate(Quest* quest) {
  6192. vector<QuestStep*>* updates = quest->GetQuestUpdates();
  6193. if (updates) {
  6194. QuestStep* step = 0;
  6195. bool updated = false;
  6196. for (int32 i = 0; i < updates->size(); i++) {
  6197. step = updates->at(i);
  6198. if (lua_interface && step->Complete() && quest->GetCompleteAction(step->GetStepID()))
  6199. {
  6200. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(step->GetStepID()), player);
  6201. SendQuestUpdateStep(quest, step->GetStepID());
  6202. updated = true;
  6203. }
  6204. if (step->WasUpdated()) {
  6205. // reversing the order of SendQuestJournal and QueuePacket QuestJournalReply causes AoM client to crash!
  6206. SendQuestJournal(false, 0, true);
  6207. if(!updated)
  6208. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step));
  6209. updated = true;
  6210. }
  6211. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6212. }
  6213. if (lua_interface && quest->GetCompleted() && quest->GetCompleteAction()) {
  6214. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(), player);
  6215. SendQuestJournalUpdate(quest, true);
  6216. }
  6217. if (quest->GetCompleted()) {
  6218. if (quest->GetQuestReturnNPC() > 0)
  6219. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestReturnNPC(), this, false, true);
  6220. if (quest->GetCompletedFlag())
  6221. quest->SetCompletedFlag(false);
  6222. }
  6223. updates->clear();
  6224. }
  6225. }
  6226. void Client::SendQuestJournal(bool all_quests, Client* client, bool updated) {
  6227. if (!client)
  6228. client = this;
  6229. PacketStruct* packet = player->GetQuestJournalPacket(all_quests, GetVersion(), GetNameCRC(), current_quest_id, updated);
  6230. if (packet) {
  6231. EQ2Packet* outapp = packet->serialize();
  6232. //DumpPacket(outapp);
  6233. client->QueuePacket(outapp);
  6234. safe_delete(packet);
  6235. }
  6236. }
  6237. void Client::SendQuestJournalUpdate(Quest* quest, bool updated) {
  6238. PacketStruct* packet = player->GetQuestJournalPacket(quest, GetVersion(), GetNameCRC(), updated);
  6239. if (packet) {
  6240. QueuePacket(packet->serialize());
  6241. safe_delete(packet);
  6242. }
  6243. }
  6244. void Client::ReloadQuests() {
  6245. vector<int32> ids = player->GetQuestIDs();
  6246. Quest* quest = 0;
  6247. for (int32 i = 0; i < ids.size(); i++) {
  6248. quest = master_quest_list.GetQuest(ids[i]);
  6249. if (quest)
  6250. AddPlayerQuest(quest, false);
  6251. else
  6252. RemovePlayerQuest(ids[i]);
  6253. }
  6254. }
  6255. Quest* Client::GetPendingQuestAcceptance(int32 item_id) {
  6256. std::unique_lock lock(MPendingQuestAccept);
  6257. bool found_quest = false;
  6258. vector<int32>::iterator itr;
  6259. int32 questID = 0;
  6260. Quest* quest = nullptr;
  6261. for (itr = pending_quest_accept.begin(); itr != pending_quest_accept.end();) {
  6262. questID = *itr;
  6263. bool quest_exists = false;
  6264. quest = GetPlayer()->PendingQuestAcceptance(questID, item_id, &quest_exists);
  6265. if(!quest_exists) {
  6266. LogWrite(CCLIENT__ERROR, 0, "Client", "Quest ID %u missing for Player %s, removing quest id from pending_quest_accept.", questID, GetPlayer()->GetName());
  6267. itr = pending_quest_accept.erase(itr);
  6268. quest = nullptr;
  6269. continue;
  6270. }
  6271. else if (quest) {
  6272. pending_quest_accept.erase(itr);
  6273. break;
  6274. }
  6275. itr++;
  6276. }
  6277. return quest;
  6278. }
  6279. void Client::AcceptQuestReward(Quest* quest, int32 item_id) {
  6280. int8 num_slots_needed = 0;
  6281. int16 free_slots = player->item_list.GetNumberOfFreeSlots();
  6282. Item* master_item = 0;
  6283. if (item_id > 0) {
  6284. num_slots_needed++;
  6285. master_item = master_item_list.GetItem(item_id);
  6286. }
  6287. int32 totalItems = 0;
  6288. vector<Item*>* items = 0;
  6289. vector<Item*>* tmpItems = 0;
  6290. bool isTempState = quest->GetQuestTemporaryState();
  6291. if(isTempState)
  6292. {
  6293. tmpItems = quest->GetTmpRewardItems();
  6294. if (tmpItems && tmpItems->size() > 0)
  6295. {
  6296. num_slots_needed += tmpItems->size();
  6297. totalItems += tmpItems->size();
  6298. }
  6299. }
  6300. else
  6301. {
  6302. items = quest->GetRewardItems();
  6303. if (items && items->size() > 0)
  6304. {
  6305. num_slots_needed += items->size();
  6306. totalItems += items->size();
  6307. }
  6308. }
  6309. RemoveQueuedQuestReward();
  6310. GetPlayer()->SetActiveReward(false);
  6311. if (free_slots >= num_slots_needed || (player->item_list.HasFreeBagSlot() && master_item && master_item->IsBag() && master_item->bag_info->num_slots >= totalItems)) {
  6312. if (master_item)
  6313. AddItem(item_id);
  6314. if (tmpItems && tmpItems->size() > 0) {
  6315. for (int32 i = 0; i < tmpItems->size(); i++)
  6316. AddItem(new Item(tmpItems->at(i)));
  6317. }
  6318. if (items && items->size() > 0) {
  6319. for (int32 i = 0; i < items->size(); i++)
  6320. AddItem(new Item(items->at(i)));
  6321. }
  6322. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6323. if (outapp)
  6324. QueuePacket(outapp);
  6325. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  6326. map<int32, sint32>::iterator itr;
  6327. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  6328. int32 faction_id = itr->first;
  6329. sint32 amount = itr->second;
  6330. if (amount > 0)
  6331. player->GetFactions()->IncreaseFaction(faction_id, amount);
  6332. else
  6333. player->GetFactions()->DecreaseFaction(faction_id, (amount * -1));
  6334. }
  6335. if(quest->GetQuestTemporaryState())
  6336. {
  6337. int64 total_coins = quest->GetCoinTmpReward();
  6338. if (total_coins > 0)
  6339. AwardCoins(total_coins, std::string("for completing ").append(quest->GetName()));
  6340. player->GetInfoStruct()->add_status_points(quest->GetStatusTmpReward());
  6341. }
  6342. else {
  6343. player->GetInfoStruct()->add_status_points(quest->GetStatusPoints());
  6344. }
  6345. quest->SetQuestTemporaryState(false);
  6346. player->SetCharSheetChanged(true);
  6347. }
  6348. else {
  6349. GetPlayer()->SetActiveReward(true);
  6350. AddPendingQuestAcceptReward(quest);
  6351. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots! Free some slots and try again.");
  6352. DisplayQuestComplete(quest, quest->GetQuestTemporaryState(), quest->GetQuestTemporaryDescription());
  6353. }
  6354. }
  6355. 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) {
  6356. 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))) {
  6357. /*if (quest)
  6358. text = quest->GetName();
  6359. else*/
  6360. return;//nothing to give
  6361. }
  6362. GetPlayer()->ClearPendingSelectableItemRewards(0, true);
  6363. GetPlayer()->ClearPendingItemRewards();
  6364. PacketStruct* packet2 = configReader.getStruct("WS_QuestRewardPackMsg", GetVersion());
  6365. if (packet2) {
  6366. int32 source_id = 0;
  6367. if (quest)
  6368. source_id = quest->GetQuestID();
  6369. int64 rewarded_coin = 0;
  6370. if (quest) {
  6371. if (quest->GetCoinsReward() > 0) {
  6372. if (quest->GetCoinsRewardMax() > 0)
  6373. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  6374. else
  6375. rewarded_coin = quest->GetCoinsReward();
  6376. }
  6377. quest->SetGeneratedCoin(rewarded_coin);
  6378. }
  6379. if (rewarded_coin > coin)
  6380. coin = rewarded_coin;
  6381. 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
  6382. if (coin > 0) {
  6383. player->AddCoins(coin);
  6384. PlaySound("coin_cha_ching");
  6385. }
  6386. }
  6387. packet2->setSubstructDataByName("reward_data", "unknown1", 255);
  6388. packet2->setSubstructDataByName("reward_data", "reward", header);
  6389. packet2->setSubstructDataByName("reward_data", "max_coin", coin);
  6390. if (player->GetGuild() && !was_displayed) {
  6391. 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
  6392. player->GetInfoStruct()->add_status_points(status_points);
  6393. player->SetCharSheetChanged(true);
  6394. }
  6395. packet2->setSubstructDataByName("reward_data", "status_points", status_points);
  6396. }
  6397. if(text)
  6398. packet2->setSubstructDataByName("reward_data", "text", text);
  6399. std::vector<Item*> items;
  6400. quest->GetTmpRewardItemsByID(&items);
  6401. if(rewards || items.size() > 0){
  6402. int32 item_count = items.size();
  6403. item_count += rewards ? rewards->size() : 0;
  6404. packet2->setSubstructArrayLengthByName("reward_data", "num_rewards", item_count);
  6405. int i = 0;
  6406. if(rewards) {
  6407. for (i = 0; i < rewards->size(); i++) {
  6408. Item* item = rewards->at(i);
  6409. if (item) {
  6410. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  6411. packet2->setItemArrayDataByName("item", item, player, i, 0, GetClientItemPacketOffset());
  6412. }
  6413. 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
  6414. player->AddPendingItemReward(item); //item reference will be deleted after the player accepts it
  6415. }
  6416. }
  6417. for (int j = 0; j < items.size(); j++) {
  6418. Item* item = items.at(j);
  6419. if (item) {
  6420. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  6421. packet2->setItemArrayDataByName("item", item, player, i, 0, GetClientItemPacketOffset());
  6422. }
  6423. 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
  6424. player->AddPendingItemReward(item); //item reference will be deleted after the player accepts it
  6425. i++;
  6426. }
  6427. }
  6428. if (selectable_rewards) {
  6429. packet2->setSubstructArrayLengthByName("reward_data", "num_select_rewards", selectable_rewards->size());
  6430. for (int i = 0; i < selectable_rewards->size(); i++) {
  6431. Item* item = selectable_rewards->at(i);
  6432. if (item) {
  6433. packet2->setArrayDataByName("select_reward_id", item->details.item_id, i);
  6434. packet2->setItemArrayDataByName("select_item", item, player, i, 0, GetClientItemPacketOffset());
  6435. 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
  6436. player->AddPendingSelectableItemReward(source_id, item); //item reference will be deleted after the player selects one
  6437. }
  6438. }
  6439. }
  6440. if (factions) {
  6441. map<int32, sint32>::iterator itr;
  6442. map<Faction*, signed int> factions_map;
  6443. for (itr = factions->begin(); itr != factions->end(); itr++) {
  6444. Faction* faction = master_faction_list.GetFaction(itr->first);
  6445. if (faction)
  6446. factions_map[faction] = itr->second;
  6447. }
  6448. packet2->setSubstructArrayLengthByName("reward_data", "num_factions", factions_map.size());
  6449. map<Faction*, signed int>::iterator faction_itr;
  6450. int8 i = 0;
  6451. for (faction_itr = factions_map.begin(); faction_itr != factions_map.end(); faction_itr++) {
  6452. packet2->setArrayDataByName("faction_name", faction_itr->first->name.c_str(), i);
  6453. sint32 amount = faction_itr->second;
  6454. packet2->setArrayDataByName("amount", amount, i);
  6455. if (!quest) { //this entire function is for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  6456. if (amount > 0)
  6457. player->GetFactions()->IncreaseFaction(faction_itr->first->id, amount);
  6458. else
  6459. player->GetFactions()->DecreaseFaction(faction_itr->first->id, (amount * -1));
  6460. }
  6461. i++;
  6462. }
  6463. }
  6464. QueuePacket(packet2->serialize());
  6465. safe_delete(packet2);
  6466. }
  6467. }
  6468. void Client::PopulateQuestRewardItems(vector <Item*>* items, PacketStruct* packet,
  6469. std::string num_rewards_str, std::string reward_id_str, std::string item_str) {
  6470. if(!items || !packet)
  6471. return;
  6472. if (items) {
  6473. int32 total_item_count = 0;
  6474. for(int s=0;s<items->size();s++) {
  6475. Item* tmpItem = items->at(s);
  6476. if(tmpItem) {
  6477. if(tmpItem->details.count > 1) {
  6478. total_item_count += tmpItem->details.count;
  6479. }
  6480. else {
  6481. total_item_count += 1;
  6482. }
  6483. }
  6484. }
  6485. packet->setArrayLengthByName(num_rewards_str.c_str(), total_item_count);
  6486. int16 count = 0;
  6487. int16 pos = 0;
  6488. for (int32 i = 0; i < items->size();) {
  6489. packet->setArrayDataByName(reward_id_str.c_str(), items->at(i)->details.item_id, pos);
  6490. if (version < 860)
  6491. packet->setItemArrayDataByName(item_str.c_str(), items->at(i), player, pos, 0, GetClientItemPacketOffset());
  6492. else if (version < 1193)
  6493. packet->setItemArrayDataByName(item_str.c_str(), items->at(i), player, pos);
  6494. else
  6495. packet->setItemArrayDataByName(item_str.c_str(), items->at(i), player, pos, 0, 2);
  6496. pos++;
  6497. if(count >= items->at(i)->details.count-1) {
  6498. count = 0;
  6499. }
  6500. else if(items->at(i)->details.count > 1) {
  6501. count++;
  6502. continue;
  6503. }
  6504. i++;
  6505. }
  6506. }
  6507. }
  6508. void Client::DisplayQuestComplete(Quest* quest, bool tempReward, std::string customDescription, bool was_displayed) {
  6509. if (!quest)
  6510. return;
  6511. if (GetVersion() <= 561) {
  6512. DisplayQuestRewards(quest, 0, quest->GetRewardItems(), quest->GetSelectableRewardItems(), quest->GetRewardFactions(), "Quest Complete!", quest->GetStatusPoints(), tempReward ? customDescription.c_str() : quest->GetCompletedDescription(), was_displayed);
  6513. return;
  6514. }
  6515. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", GetVersion());
  6516. if (packet) {
  6517. packet->setDataByName("title", "Quest Reward!");
  6518. packet->setDataByName("name", quest->GetName());
  6519. if(tempReward)
  6520. {
  6521. packet->setDataByName("description", customDescription.c_str());
  6522. }
  6523. else
  6524. packet->setDataByName("description", quest->GetCompletedDescription());
  6525. packet->setDataByName("level", quest->GetLevel());
  6526. packet->setDataByName("encounter_level", quest->GetEncounterLevel());
  6527. int8 difficulty = 0;
  6528. if ((string)quest->GetType() == "Tradeskill")
  6529. difficulty = player->GetTSArrowColor(quest->GetLevel());
  6530. else
  6531. difficulty = player->GetArrowColor(quest->GetLevel());
  6532. packet->setDataByName("difficulty", difficulty);
  6533. if(tempReward)
  6534. {
  6535. packet->setDataByName("max_coin", quest->GetCoinTmpReward());
  6536. packet->setDataByName("min_coin", quest->GetCoinTmpReward());
  6537. packet->setDataByName("status_points", quest->GetStatusPoints());
  6538. }
  6539. else
  6540. {
  6541. int64 rewarded_coin = 0;
  6542. if (quest->GetCoinsReward() > 0) {
  6543. if (quest->GetCoinsRewardMax() > 0)
  6544. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  6545. else
  6546. rewarded_coin = quest->GetCoinsReward();
  6547. }
  6548. quest->SetGeneratedCoin(rewarded_coin);
  6549. packet->setDataByName("max_coin", rewarded_coin);
  6550. packet->setDataByName("min_coin", rewarded_coin);
  6551. packet->setDataByName("status_points", quest->GetStatusPoints());
  6552. }
  6553. if(tempReward) {
  6554. PopulateQuestRewardItems(quest->GetTmpRewardItems(), packet);
  6555. }
  6556. else
  6557. {
  6558. vector<Item*>* items2 = quest->GetSelectableRewardItems();
  6559. PopulateQuestRewardItems(quest->GetRewardItems(), packet);
  6560. PopulateQuestRewardItems(quest->GetSelectableRewardItems(), packet, std::string("num_select_rewards"),
  6561. std::string("select_reward_id"), std::string("select_item"));
  6562. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  6563. if (reward_factions && reward_factions->size() > 0) {
  6564. packet->setArrayLengthByName("num_factions", reward_factions->size());
  6565. map<int32, sint32>::iterator itr;
  6566. int16 index = 0;
  6567. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  6568. int32 faction_id = itr->first;
  6569. sint32 amount = itr->second;
  6570. const char* faction_name = master_faction_list.GetFactionNameByID(faction_id);
  6571. if (faction_name) {
  6572. packet->setArrayDataByName("faction_name", const_cast<char*>(faction_name), index);
  6573. packet->setArrayDataByName("amount", amount, index);
  6574. }
  6575. index++;
  6576. }
  6577. }
  6578. }
  6579. EQ2Packet* outapp = packet->serialize();
  6580. // DumpPacket(outapp);
  6581. QueuePacket(outapp);
  6582. safe_delete(packet);
  6583. }
  6584. }
  6585. void Client::DisplayRandomizeFeatures(int32 flags) {
  6586. SimpleMessage(CHANNEL_NARRATIVE, "Showing Active Randomize Features:");
  6587. if (flags > 0) {
  6588. if (flags & RANDOMIZE_GENDER)
  6589. SimpleMessage(CHANNEL_NARRATIVE, "- Gender");
  6590. if (flags & RANDOMIZE_RACE)
  6591. SimpleMessage(CHANNEL_NARRATIVE, "- Race");
  6592. if (flags & RANDOMIZE_MODEL_TYPE)
  6593. SimpleMessage(CHANNEL_NARRATIVE, "- Model");
  6594. if (flags & RANDOMIZE_FACIAL_HAIR_TYPE)
  6595. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair");
  6596. if (flags & RANDOMIZE_HAIR_TYPE)
  6597. SimpleMessage(CHANNEL_NARRATIVE, "- Hair");
  6598. if (flags & RANDOMIZE_WING_TYPE)
  6599. SimpleMessage(CHANNEL_NARRATIVE, "- Wing");
  6600. if (flags & RANDOMIZE_CHEEK_TYPE)
  6601. SimpleMessage(CHANNEL_NARRATIVE, "- Cheek");
  6602. if (flags & RANDOMIZE_CHIN_TYPE)
  6603. SimpleMessage(CHANNEL_NARRATIVE, "- Chin");
  6604. if (flags & RANDOMIZE_EAR_TYPE)
  6605. SimpleMessage(CHANNEL_NARRATIVE, "- Ear");
  6606. if (flags & RANDOMIZE_EYE_BROW_TYPE)
  6607. SimpleMessage(CHANNEL_NARRATIVE, "- Eyebrow");
  6608. if (flags & RANDOMIZE_EYE_TYPE)
  6609. SimpleMessage(CHANNEL_NARRATIVE, "- Eye");
  6610. if (flags & RANDOMIZE_LIP_TYPE)
  6611. SimpleMessage(CHANNEL_NARRATIVE, "- Lip");
  6612. if (flags & RANDOMIZE_NOSE_TYPE)
  6613. SimpleMessage(CHANNEL_NARRATIVE, "- Nose");
  6614. if (flags & RANDOMIZE_EYE_COLOR)
  6615. SimpleMessage(CHANNEL_NARRATIVE, "- Eye Color");
  6616. if (flags & RANDOMIZE_HAIR_COLOR1)
  6617. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color1");
  6618. if (flags & RANDOMIZE_HAIR_COLOR2)
  6619. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color2");
  6620. if (flags & RANDOMIZE_HAIR_HIGHLIGHT)
  6621. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color Highlights");
  6622. if (flags & RANDOMIZE_HAIR_FACE_COLOR)
  6623. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color");
  6624. if (flags & RANDOMIZE_HAIR_FACE_HIGHLIGHT_COLOR)
  6625. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color Highlights");
  6626. if (flags & RANDOMIZE_HAIR_TYPE_COLOR)
  6627. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Color");
  6628. if (flags & RANDOMIZE_HAIR_TYPE_HIGHLIGHT_COLOR)
  6629. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Highlights");
  6630. if (flags & RANDOMIZE_SKIN_COLOR)
  6631. SimpleMessage(CHANNEL_NARRATIVE, "- Skin Color");
  6632. if (flags & RANDOMIZE_WING_COLOR1)
  6633. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color1");
  6634. if (flags & RANDOMIZE_WING_COLOR2)
  6635. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color2");
  6636. }
  6637. else
  6638. {
  6639. SimpleMessage(CHANNEL_NARRATIVE, "- No Randomization Set.");
  6640. }
  6641. }
  6642. void Client::GiveQuestReward(Quest* quest, bool has_displayed) {
  6643. current_quest_id = 0;
  6644. if(!quest->GetQuestTemporaryState() && !has_displayed)
  6645. {
  6646. quest->IncrementCompleteCount();
  6647. player->AddCompletedQuest(quest);
  6648. }
  6649. AddPendingQuestAcceptReward(quest);
  6650. DisplayQuestComplete(quest, quest->GetQuestTemporaryState(), quest->GetQuestTemporaryDescription());
  6651. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6652. SendQuestJournal();
  6653. if(quest->GetQuestTemporaryState()) {
  6654. return;
  6655. }
  6656. if(!has_displayed) {
  6657. if (quest->GetExpReward() > 0) {
  6658. int32 xp = quest->GetExpReward();
  6659. player->AddXP(xp);
  6660. }
  6661. if (quest->GetTSExpReward() > 0) {
  6662. int8 ts_level = player->GetTSLevel();
  6663. int32 xp = quest->GetTSExpReward();
  6664. if (player->AddTSXP(xp)) {
  6665. Message(CHANNEL_REWARD, "You gain %u tradeskill experience!", (int32)xp);
  6666. if (player->GetTSLevel() != ts_level)
  6667. ChangeTSLevel(ts_level, player->GetTSLevel());
  6668. player->SetCharSheetChanged(true);
  6669. }
  6670. }
  6671. int64 total_coins = quest->GetGeneratedCoin();
  6672. if (total_coins > 0)
  6673. AwardCoins(total_coins, std::string("for completing ").append(quest->GetName()));
  6674. player->RemoveQuest(quest->GetQuestID(), false);
  6675. }
  6676. if (quest->GetQuestGiver() > 0)
  6677. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  6678. if(!has_displayed) {
  6679. RemovePlayerQuest(quest->GetQuestID(), true, false);
  6680. }
  6681. }
  6682. 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) {
  6683. std::unique_lock lock(MConversation);
  6684. PacketStruct* packet = configReader.getStruct("WS_DialogOpen", GetVersion());
  6685. if (packet) {
  6686. packet->setDataByName("conversation_id", conversation_id);
  6687. packet->setDataByName("text", text);
  6688. packet->setDataByName("language", language); // default 0
  6689. packet->setDataByName("enable_blue_ui", 0); // default 0
  6690. packet->setDataByName("can_close", can_close); // default 1
  6691. conversation_map[conversation_id].clear();
  6692. if (conversations) {
  6693. packet->setArrayLengthByName("num_responses", conversations->size());
  6694. for (int32 i = 0; i < conversations->size(); i++) {
  6695. packet->setArrayDataByName("response", conversations->at(i).option.c_str(), i);
  6696. if (conversations->at(i).function.length() > 0)
  6697. conversation_map[conversation_id][i] = conversations->at(i).function;
  6698. }
  6699. }
  6700. packet->setDataByName("spawn_id", spawn_id);
  6701. if (mp3) {
  6702. packet->setDataByName("voice", mp3);
  6703. packet->setDataByName("key1", key1);
  6704. packet->setDataByName("key2", key2);
  6705. }
  6706. QueuePacket(packet->serialize());
  6707. safe_delete(packet);
  6708. }
  6709. }
  6710. 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) {
  6711. if (!item || !text || !conversations || conversations->size() == 0) {
  6712. return;
  6713. }
  6714. int32 conversation_id = GetConversationID(0, item);
  6715. if (conversation_id == 0) {
  6716. next_conversation_id++;
  6717. conversation_id = next_conversation_id;
  6718. }
  6719. MConversation.lock();
  6720. conversation_items[conversation_id] = item;
  6721. MConversation.unlock();
  6722. if (type == 4)
  6723. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2, language, can_close);
  6724. else
  6725. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2, language, can_close);
  6726. }
  6727. 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) {
  6728. if (!src || !(type == 1 || type == 2 || type == 3) || !text /*|| !conversations || conversations->size() == 0*/) {
  6729. return;
  6730. }
  6731. int32 conversation_id = GetConversationID(src, 0);
  6732. if (conversation_id == 0) {
  6733. next_conversation_id++;
  6734. conversation_id = next_conversation_id;
  6735. }
  6736. MConversation.lock();
  6737. conversation_spawns[conversation_id] = src->GetID();
  6738. MConversation.unlock();
  6739. /* Spawns can start two different types of conversations.
  6740. * Type 1: The chat type with bubbles.
  6741. * Type 2: The dialog type with the blue box. */
  6742. if (type == 1)
  6743. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(src), conversations, text, mp3, key1, key2, language, can_close);
  6744. else if (type == 2)
  6745. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2, language, can_close);
  6746. else //if (type == 3)
  6747. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2, language, can_close);
  6748. }
  6749. void Client::CloseDialog(int32 conversation_id) {
  6750. std::unique_lock lock(MConversation);
  6751. PacketStruct* packet = configReader.getStruct("WS_ServerDialogClose", GetVersion());
  6752. if (packet) {
  6753. packet->setDataByName("conversation_id", conversation_id);
  6754. QueuePacket(packet->serialize());
  6755. safe_delete(packet);
  6756. }
  6757. std::map<int32, Item*>::iterator itr;
  6758. while((itr = conversation_items.find(conversation_id)) != conversation_items.end())
  6759. {
  6760. conversation_items.erase(itr);
  6761. }
  6762. std::map<int32, int32>::iterator itr2 = conversation_spawns.find(conversation_id);
  6763. while((itr2 = conversation_spawns.find(conversation_id)) != conversation_spawns.end())
  6764. {
  6765. conversation_spawns.erase(itr2);
  6766. }
  6767. }
  6768. int32 Client::GetConversationID(Spawn* spawn, Item* item) {
  6769. std::shared_lock lock(MConversation);
  6770. int32 conversation_id = 0;
  6771. if (spawn) {
  6772. map<int32, int32>::iterator itr;
  6773. for (itr = conversation_spawns.begin(); itr != conversation_spawns.end(); itr++) {
  6774. if (itr->second == spawn->GetID()) {
  6775. conversation_id = itr->first;
  6776. break;
  6777. }
  6778. }
  6779. }
  6780. else if (item) {
  6781. map<int32, Item*>::iterator itr;
  6782. for (itr = conversation_items.begin(); itr != conversation_items.end(); itr++) {
  6783. if (itr->second == item) {
  6784. conversation_id = itr->first;
  6785. break;
  6786. }
  6787. }
  6788. }
  6789. return conversation_id;
  6790. }
  6791. Spawn* Client::GetCombineSpawn() {
  6792. return combine_spawn;
  6793. }
  6794. bool Client::ShouldTarget() {
  6795. return should_target;
  6796. }
  6797. void Client::TargetSpawn(Spawn* spawn) {
  6798. should_target = false;
  6799. PacketStruct* packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  6800. if (packet) {
  6801. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  6802. QueuePacket(packet->serialize());
  6803. safe_delete(packet);
  6804. }
  6805. }
  6806. void Client::CombineSpawns(float radius, Spawn* spawn) {
  6807. combine_spawn = spawn;
  6808. spawn->RemoveSpawnFromGroup(true);
  6809. if (!GetCurrentZone()->AddCloseSpawnsToSpawnGroup(combine_spawn, radius))
  6810. SimpleMessage(CHANNEL_COLOR_YELLOW, "One or more spawns are in a spawn group and cannot be combined until they are removed from their group.");
  6811. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  6812. should_target = true;
  6813. }
  6814. void Client::AddCombineSpawn(Spawn* spawn) {
  6815. if (combine_spawn && combine_spawn != spawn && spawn) {
  6816. combine_spawn->AddSpawnToGroup(spawn);
  6817. spawn->AddSpawnToGroup(combine_spawn);
  6818. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  6819. }
  6820. else if (spawn)
  6821. combine_spawn = spawn;
  6822. should_target = true;
  6823. }
  6824. void Client::RemoveCombineSpawn(Spawn* spawn) {
  6825. if (combine_spawn && spawn)
  6826. spawn->RemoveSpawnFromGroup();
  6827. if (combine_spawn == spawn)
  6828. combine_spawn->RemoveSpawnFromGroup(true);
  6829. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  6830. if (combine_spawn == spawn)
  6831. combine_spawn = 0;
  6832. }
  6833. void Client::SaveCombineSpawns(const char* name) {
  6834. if (!combine_spawn) {
  6835. return;
  6836. }
  6837. vector<Spawn*>* spawns = combine_spawn->GetSpawnGroup();
  6838. if (!spawns) {
  6839. return;
  6840. }
  6841. int32 count = spawns->size();
  6842. int32 spawnLocationID = 0;
  6843. if (count == 1)
  6844. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error: You only have a single Spawn in the group!");
  6845. else if ((spawnLocationID = database.SaveCombinedSpawnLocation(GetCurrentZone(), combine_spawn, name)) > 0) {
  6846. Message(CHANNEL_COLOR_YELLOW, "Successfully combined %u spawns into spawn location: %u", count, spawnLocationID);
  6847. // we remove the spawn inside SaveCombinedSpawnLocation
  6848. //GetCurrentZone()->RemoveSpawn(combine_spawn);
  6849. }
  6850. else
  6851. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn group, check console for details.");
  6852. safe_delete(spawns);
  6853. combine_spawn = 0;
  6854. }
  6855. bool Client::AddItem(int32 item_id, int16 quantity, AddItemType type) {
  6856. Item* master_item = master_item_list.GetItem(item_id);
  6857. Item* item = 0;
  6858. if (master_item)
  6859. item = new Item(master_item);
  6860. if (item) {
  6861. if (quantity > 0)
  6862. item->details.count = quantity;
  6863. return AddItem(item, nullptr, type);
  6864. }
  6865. else
  6866. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  6867. return false;
  6868. }
  6869. bool Client::AddItem(Item* item, bool* item_deleted, AddItemType type) {
  6870. if (!item) {
  6871. return false;
  6872. }
  6873. if (player->AddItem(item, type)) {
  6874. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6875. if (outapp) {
  6876. //DumpPacket(outapp);
  6877. QueuePacket(outapp);
  6878. //resend bag desc with new item name added
  6879. outapp = player->SendBagUpdate(item->details.unique_id, GetVersion());
  6880. if (outapp) {
  6881. //DumpPacket(outapp);
  6882. QueuePacket(outapp);
  6883. }
  6884. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  6885. DumpPacket(app);
  6886. client->QueuePacket(app);
  6887. */
  6888. }
  6889. CheckPlayerQuestsItemUpdate(item);
  6890. if (item->GetItemScript() && lua_interface)
  6891. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  6892. }
  6893. else {
  6894. lua_interface->SetLuaUserDataStale(item);
  6895. // likely lore conflict
  6896. if(item_deleted)
  6897. *item_deleted = true;
  6898. return false;
  6899. }
  6900. return true;
  6901. }
  6902. bool Client::AddItemToBank(int32 item_id, int16 quantity) {
  6903. Item* master_item = master_item_list.GetItem(item_id);
  6904. Item* item = 0;
  6905. if (master_item)
  6906. item = new Item(master_item);
  6907. if (item) {
  6908. if (quantity > 0)
  6909. item->details.count = quantity;
  6910. return AddItemToBank(item);
  6911. }
  6912. else
  6913. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  6914. return false;
  6915. }
  6916. bool Client::AddItemToBank(Item* item) {
  6917. if (!item) {
  6918. return false;
  6919. }
  6920. if (player->AddItemToBank(item)) {
  6921. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6922. if (outapp) {
  6923. QueuePacket(outapp);
  6924. //resend bag desc with new item name added
  6925. outapp = player->SendBagUpdate(item->details.inv_slot_id, GetVersion());
  6926. if (outapp)
  6927. QueuePacket(outapp);
  6928. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  6929. DumpPacket(app);
  6930. client->QueuePacket(app);
  6931. */
  6932. }
  6933. CheckPlayerQuestsItemUpdate(item);
  6934. if (item->GetItemScript() && lua_interface)
  6935. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  6936. }
  6937. else {
  6938. lua_interface->SetLuaUserDataStale(item);
  6939. // likely lore conflict
  6940. safe_delete(item);
  6941. return false;
  6942. }
  6943. return true;
  6944. }
  6945. void Client::UnequipItem(int16 index, sint32 bag_id, int8 to_slot, int8 appearance_equip) {
  6946. vector<EQ2Packet*> packets = GetPlayer()->UnequipItem(index, bag_id, to_slot, GetVersion(), appearance_equip);
  6947. EQ2Packet* outapp = 0;
  6948. for(int32 i=0;i<packets.size();i++)
  6949. {
  6950. outapp = packets[i];
  6951. if(outapp)
  6952. QueuePacket(outapp);
  6953. }
  6954. GetPlayer()->UpdateWeapons();
  6955. EQ2Packet* characterSheetPackets = GetPlayer()->GetPlayerInfo()->serialize(GetVersion());
  6956. QueuePacket(characterSheetPackets);
  6957. }
  6958. bool Client::RemoveItem(Item* item, int16 quantity, bool force_override_no_delete) {
  6959. EQ2Packet* outapp;
  6960. bool delete_item = false;
  6961. assert(item);
  6962. if (quantity > 0 && !item->IsBag() && item->details.count > quantity) {
  6963. item->details.count -= quantity;
  6964. item->save_needed = true;
  6965. }
  6966. else {
  6967. database.DeleteItem(character_id, item, 0);
  6968. player->GetPlayerItemList()->RemoveItem(item, false);
  6969. delete_item = true;
  6970. }
  6971. if(force_override_no_delete)
  6972. delete_item = false;
  6973. if ((outapp = player->SendInventoryUpdate(version))) {
  6974. QueuePacket(outapp);
  6975. if (item->GetItemScript() && lua_interface)
  6976. lua_interface->RunItemScript(item->GetItemScript(), "removed", item, player);
  6977. if (delete_item)
  6978. {
  6979. PurgeItem(item);
  6980. lua_interface->SetLuaUserDataStale(item);
  6981. safe_delete(item);
  6982. }
  6983. GetPlayer()->CalculateApplyWeight();
  6984. return true;
  6985. }
  6986. return false;
  6987. }
  6988. void Client::SetLuaDebugClient(bool val) {
  6989. if (val)
  6990. lua_debug_timer.Start();
  6991. lua_debug = val;
  6992. if (lua_interface && !val) {
  6993. lua_interface->RemoveDebugClients(this);
  6994. lua_debug_timer.Disable();
  6995. }
  6996. }
  6997. void Client::SetMerchantTransaction(Spawn* spawn) {
  6998. merchant_transaction = spawn;
  6999. }
  7000. Spawn* Client::GetMerchantTransaction() {
  7001. return merchant_transaction;
  7002. }
  7003. void Client::SetMailTransaction(Spawn* spawn) {
  7004. ResetSendMail(spawn ? false : true);
  7005. MMailWindowMutex.lock();
  7006. mail_transaction = spawn;
  7007. MMailWindowMutex.unlock();
  7008. }
  7009. Spawn* Client::GetMailTransaction() {
  7010. return mail_transaction;
  7011. }
  7012. void Client::PlaySound(const char* name) {
  7013. if (name) {
  7014. PacketStruct* packet = configReader.getStruct("WS_PlaySound", GetVersion());
  7015. if (packet) {
  7016. packet->setMediumStringByName("name", name);
  7017. QueuePacket(packet->serialize());
  7018. safe_delete(packet);
  7019. }
  7020. }
  7021. }
  7022. float Client::CalculateBuyMultiplier(int32 merchant_id) {
  7023. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  7024. if(multiplier){
  7025. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  7026. float diff_low = faction_val - multiplier->faction_min;
  7027. if(diff_low < 0)
  7028. diff_low*=-1;
  7029. float total_diff = multiplier->faction_max - multiplier->faction_min;
  7030. if(total_diff < 0)
  7031. total_diff*=-1;
  7032. float buy_multiplier = multiplier->high_buy_multiplier - multiplier->low_buy_multiplier;
  7033. float total1 = (diff_low/total_diff);
  7034. float final_buy_multiplier = total1*buy_multiplier + total1*multiplier->low_buy_multiplier;
  7035. return final_buy_multiplier;
  7036. }*/
  7037. return 1;
  7038. }
  7039. float Client::CalculateSellMultiplier(int32 merchant_id) {
  7040. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  7041. if(multiplier){
  7042. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  7043. float diff_low = faction_val - multiplier->faction_min;
  7044. if(diff_low < 0)
  7045. diff_low*=-1;
  7046. float total_diff = multiplier->faction_max - multiplier->faction_min;
  7047. if(total_diff < 0)
  7048. total_diff*=-1;
  7049. float sell_multiplier = multiplier->high_sell_multiplier - multiplier->low_sell_multiplier;
  7050. float total1 = (diff_low/total_diff);
  7051. float final_sell_multiplier = total1*sell_multiplier + total1*multiplier->low_sell_multiplier;
  7052. return final_sell_multiplier;
  7053. }*/
  7054. return 1;
  7055. }
  7056. void Client::SellItem(int32 item_id, int16 quantity, int32 unique_id) {
  7057. Spawn* spawn = GetMerchantTransaction();
  7058. Guild* guild = GetPlayer()->GetGuild();
  7059. if (spawn && spawn->GetMerchantID() > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY)) &&
  7060. spawn->IsClientInMerchantLevelRange(this)) {
  7061. int32 total_sell_price = 0;
  7062. int32 total_status_sell_price = 0; //for status
  7063. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  7064. int32 sell_price = 0;
  7065. int32 status_sell_price = 0; //for status
  7066. Item* master_item = master_item_list.GetItem(item_id);
  7067. Item* item = 0;
  7068. if (unique_id == 0)
  7069. item = player->item_list.GetItemFromID(item_id, quantity);
  7070. else
  7071. item = player->item_list.GetItemFromUniqueID(unique_id);
  7072. if (!item)
  7073. item = player->item_list.GetItemFromID(item_id);
  7074. if (item && master_item) {
  7075. if(item->details.item_locked)
  7076. {
  7077. SimpleMessage(CHANNEL_COLOR_RED, "You cannot sell the item in use.");
  7078. return;
  7079. }
  7080. else if(item->CheckFlag(NO_VALUE))
  7081. {
  7082. SimpleMessage(CHANNEL_COLOR_RED, "This item has no value.");
  7083. return;
  7084. }
  7085. else if (item->IsBag())
  7086. {
  7087. int32 bagitemcount = player->GetPlayerItemList()->GetItemCountInBag(item);
  7088. if (bagitemcount > 0) {
  7089. SimpleMessage(CHANNEL_COLOR_RED, "You cannot sell a bag with items inside it.");
  7090. return;
  7091. }
  7092. }
  7093. int32 sell_price = (int32)(master_item->sell_price * multiplier);
  7094. if (sell_price > item->sell_price)
  7095. sell_price = item->sell_price;
  7096. if (quantity > item->details.count)
  7097. quantity = item->details.count;
  7098. total_sell_price = sell_price * quantity;
  7099. //------------------------------For Selling Status Items
  7100. status_sell_price = (int32)(master_item->sell_status * multiplier);
  7101. if (status_sell_price > item->sell_status)
  7102. status_sell_price = item->sell_status;
  7103. if (quantity > item->details.count)
  7104. quantity = item->details.count;
  7105. total_status_sell_price = status_sell_price * quantity;
  7106. if(total_status_sell_price > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))
  7107. total_status_sell_price = 0;
  7108. player->GetInfoStruct()->add_status_points(total_status_sell_price);
  7109. int32 guildMaxLevel = 5 + item->details.recommended_level; // client hard codes +5 to the level
  7110. if (player->GetGuild() && guild->GetLevel() < guildMaxLevel) {
  7111. guild->UpdateGuildStatus(GetPlayer(), total_status_sell_price / 10);
  7112. guild->SendGuildMemberList();
  7113. guild->AddEXPCurrent((total_status_sell_price / 10), true);
  7114. }
  7115. if (quantity > 1)
  7116. {
  7117. if(total_status_sell_price)
  7118. 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);
  7119. else
  7120. 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());
  7121. }
  7122. else
  7123. {
  7124. if(total_status_sell_price)
  7125. 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);
  7126. else
  7127. 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());
  7128. }
  7129. player->AddCoins(total_sell_price);
  7130. if(!item->no_buy_back && (total_status_sell_price == 0 || (total_status_sell_price > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))))
  7131. AddBuyBack(unique_id, item_id, quantity, sell_price);
  7132. if (quantity >= item->details.count) {
  7133. database.DeleteItem(GetCharacterID(), item, 0);
  7134. player->item_list.DestroyItem(item->details.index);
  7135. }
  7136. else {
  7137. item->details.count -= quantity;
  7138. item->save_needed = true;
  7139. }
  7140. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  7141. if (outapp)
  7142. QueuePacket(outapp);
  7143. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  7144. SendBuyBackList();
  7145. }
  7146. }
  7147. }
  7148. void Client::BuyBack(int32 item_id, int16 quantity) {
  7149. Spawn* spawn = GetMerchantTransaction();
  7150. if (spawn && spawn->GetMerchantID() > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK)) &&
  7151. spawn->IsClientInMerchantLevelRange(this)) {
  7152. deque<BuyBackItem*>::iterator itr;
  7153. BuyBackItem* buyback = 0;
  7154. BuyBackItem* closest = 0;
  7155. MBuyBack.readlock(__FUNCTION__, __LINE__);
  7156. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  7157. buyback = *itr;
  7158. if (buyback->unique_id == item_id) {
  7159. closest = buyback;
  7160. quantity = buyback->quantity;
  7161. break;
  7162. }
  7163. }
  7164. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  7165. if (closest) {
  7166. Item* item = 0;
  7167. Item* master_item = master_item_list.GetItem(closest->item_id);
  7168. if (master_item) {
  7169. item = new Item(master_item);
  7170. if (closest->quantity >= quantity)
  7171. item->details.count = quantity;
  7172. else
  7173. item->details.count = closest->quantity;
  7174. }
  7175. bool itemDeleted = false;
  7176. bool itemAdded = false;
  7177. sint64 dispFlags = 0;
  7178. if (item && item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "buyback_display_flags", item, player, nullptr, &dispFlags) && (dispFlags & DISPLAY_FLAG_NO_BUY))
  7179. SimpleMessage(CHANNEL_NARRATIVE, "You do not meet all the requirements to buy this item.");
  7180. else if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item))
  7181. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  7182. else if (player->RemoveCoins(closest->quantity * closest->price)) {
  7183. bool removed = false;
  7184. if (closest->quantity == quantity) {
  7185. MBuyBack.writelock(__FUNCTION__, __LINE__);
  7186. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  7187. if (*itr == closest) {
  7188. buy_back_items.erase(itr);
  7189. removed = true;
  7190. break;
  7191. }
  7192. }
  7193. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  7194. }
  7195. else {
  7196. closest->quantity -= quantity;
  7197. closest->save_needed = true;
  7198. }
  7199. itemAdded = AddItem(item, &itemDeleted);
  7200. if (removed) {
  7201. database.DeleteBuyBack(GetCharacterID(), closest->item_id, closest->quantity, closest->price);
  7202. safe_delete(closest);
  7203. }
  7204. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  7205. SendBuyBackList();
  7206. }
  7207. else
  7208. SimpleMessage(CHANNEL_COLOR_RED, "You cannot afford this item.");
  7209. if(!itemAdded && !itemDeleted) {
  7210. lua_interface->SetLuaUserDataStale(item);
  7211. safe_delete(item);
  7212. }
  7213. }
  7214. }
  7215. }
  7216. void Client::BuyItem(int32 item_id, int16 quantity) {
  7217. // Get the merchant we are buying from
  7218. Spawn* spawn = GetMerchantTransaction();
  7219. // Make sure the spawn has a merchant list
  7220. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  7221. int32 total_buy_price = 0;
  7222. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  7223. int32 sell_price = 0;
  7224. Item* master_item = master_item_list.GetItem(item_id);
  7225. Item* item = 0;
  7226. int16 total_available = 0;
  7227. vector<MerchantItemInfo>* temp;
  7228. vector<MerchantItemInfo>::iterator itr;
  7229. MerchantItemInfo* ItemInfo = 0;
  7230. temp = world.GetMerchantList(spawn->GetMerchantID());
  7231. for (itr = temp->begin(); itr != temp->end(); itr++) {
  7232. if ((*itr).item_id == item_id) {
  7233. ItemInfo = &(*itr);
  7234. break;
  7235. }
  7236. }
  7237. if (master_item && ItemInfo) {
  7238. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO) {
  7239. quantity = 1;
  7240. total_available = 0xFFFF;
  7241. sell_price = master_item->sell_price;
  7242. }
  7243. else {
  7244. total_available = world.GetMerchantItemQuantity(spawn->GetMerchantID(), item_id);
  7245. sell_price = (int32)(master_item->sell_price * multiplier);
  7246. if (quantity > total_available)
  7247. quantity = total_available;
  7248. }
  7249. sint64 dispFlags = 0;
  7250. 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))
  7251. {
  7252. SimpleMessage(CHANNEL_NARRATIVE, "You do not meet all the requirements to buy this item.");
  7253. return;
  7254. }
  7255. if(quantity < 1)
  7256. {
  7257. SimpleMessage(CHANNEL_COLOR_RED, "Merchant does not have item for purchase (quantity < 1).");
  7258. return;
  7259. }
  7260. total_buy_price = sell_price * quantity;
  7261. item = new Item(master_item);
  7262. item->details.count = quantity;
  7263. if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item)) {
  7264. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  7265. lua_interface->SetLuaUserDataStale(item);
  7266. safe_delete(item);
  7267. }
  7268. else {
  7269. // Price not set in the merchant_inventory table, use the old method
  7270. if (ItemInfo->price_item_id == 0 && ItemInfo->price_item2_id == 0 && ItemInfo->price_status == 0 && ItemInfo->price_stationcash == 0 && ItemInfo->price_coins == 0) {
  7271. if (player->RemoveCoins(total_buy_price)) {
  7272. item->SetMaxSellValue(sell_price);
  7273. if (quantity > 1)
  7274. 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());
  7275. else
  7276. 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());
  7277. bool itemDeleted = false;
  7278. AddItem(item, &itemDeleted);
  7279. if(!itemDeleted) {
  7280. CheckPlayerQuestsItemUpdate(item);
  7281. if (item && total_available < 0xFF) {
  7282. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  7283. SendBuyMerchantList();
  7284. }
  7285. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  7286. PlayLotto(total_buy_price, item->details.item_id);
  7287. }
  7288. }
  7289. else {
  7290. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  7291. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  7292. PlaySound("buy_failed");
  7293. }
  7294. }
  7295. else {
  7296. // Price set in merchant_inventory table
  7297. // Check if the player has enough status, coins and staion cash to buy the item before checking the items
  7298. // TODO: need to add support for station cash
  7299. if (player->GetInfoStruct()->get_status_points() >= (ItemInfo->price_status * quantity) && player->HasCoins(ItemInfo->price_coins * quantity)) {
  7300. // Check items
  7301. int16 item_quantity = 0;
  7302. // Default these to true in case price_item_id or price_item2_id was never set
  7303. bool hasItem1 = true;
  7304. bool hasItem2 = true;
  7305. Item* tempItem1 = 0;
  7306. Item* tempItem2 = 0;
  7307. if (ItemInfo->price_item_id != 0) {
  7308. // Same item for whatever reason lets add the quantities together
  7309. if (ItemInfo->price_item_id == ItemInfo->price_item2_id)
  7310. item_quantity = ItemInfo->price_item_qty + ItemInfo->price_item2_qty;
  7311. else
  7312. item_quantity = ItemInfo->price_item_qty;
  7313. tempItem1 = player->item_list.GetItemFromID(ItemInfo->price_item_id);
  7314. if (tempItem1) {
  7315. if (tempItem1->details.count < item_quantity)
  7316. hasItem1 = false;
  7317. }
  7318. else {
  7319. hasItem1 = false;
  7320. }
  7321. }
  7322. // Check item2, if item_quantity is greater then item1 quantity then item2 is the same item
  7323. // as item1 and we already checked for it so we can skip this check
  7324. if (ItemInfo->price_item2_id != 0 && item_quantity <= ItemInfo->price_item_qty) {
  7325. tempItem2 = player->item_list.GetItemFromID(ItemInfo->price_item2_id);
  7326. if (tempItem2) {
  7327. if (tempItem2->details.count < ItemInfo->price_item2_qty)
  7328. hasItem2 = false;
  7329. }
  7330. else {
  7331. hasItem2 = false;
  7332. }
  7333. }
  7334. // if we have every thing then remove the price and give the item
  7335. if (hasItem1 && hasItem2) {
  7336. player->GetInfoStruct()->set_status_points(player->GetInfoStruct()->get_status_points() - (ItemInfo->price_status * quantity));
  7337. // TODO: station cash
  7338. // The update that would normally be sent after modifing the players inventory is automatically sent in AddItem wich is called later
  7339. // so there is no need to send it more then that one time
  7340. if (tempItem1) {
  7341. if (tempItem1->details.count > item_quantity) {
  7342. tempItem1->details.count -= item_quantity;
  7343. tempItem1->save_needed = true;
  7344. }
  7345. else {
  7346. database.DeleteItem(GetCharacterID(), tempItem1, 0);
  7347. player->item_list.DestroyItem(tempItem1->details.index);
  7348. }
  7349. }
  7350. if (tempItem2) {
  7351. if (tempItem2->details.count > ItemInfo->price_item2_qty) {
  7352. tempItem2->details.count -= ItemInfo->price_item2_qty;
  7353. tempItem2->save_needed = true;
  7354. }
  7355. else {
  7356. database.DeleteItem(GetCharacterID(), tempItem2, 0);
  7357. player->item_list.DestroyItem(tempItem2->details.index);
  7358. }
  7359. }
  7360. // 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
  7361. player->RemoveCoins(ItemInfo->price_coins * quantity);
  7362. item->SetMaxSellValue(sell_price);
  7363. if (quantity > 1)
  7364. 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());
  7365. else
  7366. 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());
  7367. bool itemDeleted = false;
  7368. AddItem(item, &itemDeleted);
  7369. if(!itemDeleted) {
  7370. CheckPlayerQuestsItemUpdate(item);
  7371. if (item && total_available < 0xFF) {
  7372. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  7373. SendBuyMerchantList();
  7374. }
  7375. SendSellMerchantList();
  7376. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  7377. PlayLotto(total_buy_price, item->details.item_id);
  7378. }
  7379. }
  7380. else {
  7381. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  7382. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  7383. PlaySound("buy_failed");
  7384. }
  7385. }
  7386. else {
  7387. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  7388. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  7389. PlaySound("buy_failed");
  7390. }
  7391. }
  7392. }
  7393. }
  7394. }
  7395. }
  7396. void Client::RepairItem(int32 item_id) {
  7397. Spawn* spawn = GetMerchantTransaction();
  7398. if (spawn) {
  7399. Item* item = player->item_list.GetItemFromID(item_id);
  7400. if (!item)
  7401. item = player->GetEquipmentList()->GetItemFromItemID(item_id);
  7402. if (item) {
  7403. if(item->CheckFlag2(NO_REPAIR)) {
  7404. Message(CHANNEL_MERCHANT, "The mender was unable to repair your items.");
  7405. PlaySound("buy_failed");
  7406. }
  7407. else {
  7408. int32 repair_cost = item->CalculateRepairCost();
  7409. if (player->RemoveCoins((int32)repair_cost)) {
  7410. item->generic_info.condition = 100;
  7411. item->save_needed = true;
  7412. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  7413. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  7414. QueuePacket(item->serialize(version, false, player));
  7415. Message(CHANNEL_MERCHANT, "You give %s %s to repair your %s.", spawn->GetName(), GetCoinMessage(repair_cost).c_str(), item->CreateItemLink(GetVersion()).c_str());
  7416. PlaySound("coin_cha_ching");
  7417. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  7418. SendRepairList();
  7419. }
  7420. else {
  7421. string popup_text = "You do not have enough coin to repair ";
  7422. string popup_item = item->CreateItemLink(GetVersion()).c_str();
  7423. popup_text.append(popup_item);
  7424. SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  7425. Message(CHANNEL_MERCHANT, "You do not have enough coin to repair %s.", item->CreateItemLink(GetVersion()).c_str());
  7426. PlaySound("buy_failed");
  7427. }
  7428. }
  7429. }
  7430. }
  7431. }
  7432. void Client::RepairAllItems() {
  7433. Spawn* spawn = GetMerchantTransaction();
  7434. if (spawn) {
  7435. vector<Item*>* repairable_items = GetRepairableItems();
  7436. if (repairable_items && repairable_items->size() > 0) {
  7437. vector<Item*>::iterator itr;
  7438. int64 total_cost = 0;
  7439. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++)
  7440. total_cost += (*itr)->CalculateRepairCost();
  7441. if (player->RemoveCoins((int32)total_cost)) {
  7442. Message(CHANNEL_MERCHANT, "You give %s to repair all of your items.", GetCoinMessage((int32)total_cost).c_str());
  7443. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++) {
  7444. Item* item = *itr;
  7445. if (item) {
  7446. item->generic_info.condition = 100;
  7447. item->save_needed = true;
  7448. QueuePacket(item->serialize(version, false, player));
  7449. Message(CHANNEL_COLOR_YELLOW, "Repaired: %s.", item->CreateItemLink(GetVersion()).c_str());
  7450. }
  7451. }
  7452. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  7453. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  7454. PlaySound("coin_cha_ching");
  7455. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  7456. SendRepairList();
  7457. }
  7458. else {
  7459. string popup_text = "You do not have enough coin to repair all of your items. ";
  7460. SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  7461. SimpleMessage(CHANNEL_MERCHANT, "You do not have enough coin to repair all of your items.");
  7462. PlaySound("buy_failed");
  7463. }
  7464. }
  7465. safe_delete(repairable_items);
  7466. }
  7467. }
  7468. void Client::SendAchievementsList()
  7469. {
  7470. /*map<int32, Achievement *> *achievements = player->GetAchievementList()->GetAchievements();
  7471. map<int32, Achievement *>::iterator itr;
  7472. Achievement *achievement;
  7473. vector<AchievementRequirements *> *requirements = 0;
  7474. vector<AchievementRequirements *>::iterator itr2;
  7475. AchievementRequirements *requirement;
  7476. vector<AchievementRewards *> *rewards = 0;
  7477. vector<AchievementRewards *>::iterator itr3;
  7478. AchievementRewards *reward;
  7479. PacketStruct *packet;
  7480. int16 i = 0;
  7481. int16 j = 0;
  7482. int16 k = 0;
  7483. if (!(packet = configReader.getStruct("WS_CharacterAchievements", version))) {
  7484. return;
  7485. }
  7486. packet->setArrayLengthByName("num_achievements" , achievements->size());
  7487. for (itr = achievements->begin(); itr != achievements->end(); itr++) {
  7488. achievement = itr->second;
  7489. packet->setArrayDataByName("achievement_id", achievement->GetID(), i);
  7490. packet->setArrayDataByName("title", achievement->GetTitle(), i);
  7491. packet->setArrayDataByName("uncompleted_text", achievement->GetUncompletedText(), i);
  7492. packet->setArrayDataByName("completed_text", achievement->GetCompletedText(), i);
  7493. packet->setArrayDataByName("category", achievement->GetCategory(), i);
  7494. packet->setArrayDataByName("expansion", achievement->GetExpansion(), i);
  7495. packet->setArrayDataByName("icon", achievement->GetIcon(), i);
  7496. packet->setArrayDataByName("point_value", achievement->GetPointValue(), i);
  7497. packet->setArrayDataByName("qty_req", achievement->GetQtyReq(), i);
  7498. packet->setArrayDataByName("hide_achievement", achievement->GetHide(), i);
  7499. packet->setArrayDataByName("unknown3", achievement->GetUnknown3a(), i);
  7500. packet->setArrayDataByName("unknown3", achievement->GetUnknown3b(), i);
  7501. requirements = achievement->GetRequirements();
  7502. rewards = achievement->GetRewards();
  7503. j = 0;
  7504. k = 0;
  7505. packet->setSubArrayLengthByName("num_items", requirements->size(), i, j);
  7506. for (itr2 = requirements->begin(); itr2 != requirements->end(); itr2++) {
  7507. requirement = *itr2;
  7508. packet->setSubArrayDataByName("item_name", requirement->name.c_str(), i, j);
  7509. packet->setSubArrayDataByName("item_qty_req", requirement->qty_req, i, j);
  7510. j++;
  7511. }
  7512. packet->setSubArrayLengthByName("num_rewards", achievement->GetRewards()->size(), i, k);
  7513. for (itr3 = rewards->begin(); itr3 != rewards->end(); itr3++) {
  7514. reward = *itr3;
  7515. packet->setSubArrayDataByName("reward_item", reward->reward.c_str(), i, k);
  7516. k++;
  7517. }
  7518. i++;
  7519. }
  7520. //packet->PrintPacket();
  7521. EQ2Packet* data = packet->serialize();
  7522. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  7523. safe_delete(packet);
  7524. safe_delete(data);
  7525. //DumpPacket(app);
  7526. QueuePacket(app);*/
  7527. QueuePacket(master_achievement_list.GetAchievementPacket()->Copy());
  7528. SendAchievementUpdate(true);
  7529. }
  7530. void Client::SendAchievementUpdate(bool first_login) {
  7531. map<int32, AchievementUpdate*>* updates = player->GetAchievementUpdateList()->GetAchievementUpdates();
  7532. map<int32, AchievementUpdate*>::iterator itr;
  7533. AchievementUpdate* update;
  7534. vector<AchievementUpdateItems*>* update_items = 0;
  7535. vector<AchievementUpdateItems*>::iterator itr2;
  7536. AchievementUpdateItems* update_item;
  7537. int16 i = 0;
  7538. int16 j = 0;
  7539. PacketStruct* packet;
  7540. if (!(packet = configReader.getStruct("WS_AchievementUpdate", version))) {
  7541. return;
  7542. }
  7543. packet->setDataByName("unknown1", first_login ? 1 : 0);
  7544. packet->setArrayLengthByName("num_achievements", updates->size());
  7545. for (itr = updates->begin(); itr != updates->end(); itr++) {
  7546. update = itr->second;
  7547. packet->setArrayDataByName("achievement_id", update->GetID(), i);
  7548. packet->setArrayDataByName("completed_date", update->GetCompletedDate(), i);
  7549. update_items = update->GetUpdateItems();
  7550. j = 0;
  7551. packet->setSubArrayLengthByName("num_items", update_items->size(), i);
  7552. for (itr2 = update_items->begin(); itr2 != update_items->end(); itr2++) {
  7553. update_item = *itr2;
  7554. packet->setSubArrayDataByName("item_update", update_item->item_update, i, j);
  7555. j++;
  7556. }
  7557. i++;
  7558. }
  7559. //packet->PrintPacket();
  7560. EQ2Packet* data = packet->serialize();
  7561. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  7562. safe_delete(packet);
  7563. safe_delete(data);
  7564. //DumpPacket(app);
  7565. QueuePacket(app);
  7566. }
  7567. void Client::SendBuyMerchantList(bool sell) {
  7568. Spawn* spawn = GetMerchantTransaction();
  7569. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  7570. vector<MerchantItemInfo>* items = world.GetMerchantItemList(spawn->GetMerchantID(), spawn->GetMerchantType(), player);
  7571. if (items) {
  7572. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7573. if (packet) {
  7574. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  7575. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7576. packet->setArrayLengthByName("num_items", items->size());
  7577. vector<MerchantItemInfo>::iterator itr;
  7578. sint8 item_difficulty = 0;
  7579. int32 sell_price = 0;
  7580. int i = 0;
  7581. int tmp_level = 0;
  7582. for (itr = items->begin(); itr != items->end(); itr++, i++) {
  7583. MerchantItemInfo ItemInfo = *itr;
  7584. Item* item = master_item_list.GetItem(ItemInfo.item_id);
  7585. if (!item)
  7586. continue;
  7587. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  7588. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7589. packet->setArrayDataByName("stack_size", item->stack_count, i);
  7590. packet->setArrayDataByName("icon", item->details.icon, i);
  7591. if (item->generic_info.adventure_default_level > 0)
  7592. tmp_level = item->generic_info.adventure_default_level;
  7593. else
  7594. tmp_level = item->generic_info.tradeskill_default_level;
  7595. packet->setArrayDataByName("level", tmp_level, i);
  7596. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  7597. packet->setArrayDataByName("tier", item->details.tier, i);
  7598. }
  7599. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  7600. item_difficulty = player->GetArrowColor(tmp_level);
  7601. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7602. item_difficulty = ARROW_COLOR_WHITE;
  7603. sint64 overrideValue = 0;
  7604. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "item_difficulty", item, player, nullptr, &overrideValue))
  7605. item_difficulty = (sint8)overrideValue;
  7606. item_difficulty -= 6;
  7607. if (item_difficulty < 0)
  7608. item_difficulty *= -1;
  7609. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7610. packet->setArrayDataByName("quantity", ItemInfo.quantity, i);
  7611. packet->setArrayDataByName("unknown5", 255, i);
  7612. packet->setArrayDataByName("stack_size2", item->stack_count, i);
  7613. sint64 dispFlags = 0;
  7614. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "buy_display_flags", item, player, nullptr, &dispFlags))
  7615. packet->setArrayDataByName("display_flags", (int8)dispFlags, i);
  7616. std::string overrideValueStr;
  7617. // 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)
  7618. if (GetVersion() >= 546 && item->GetItemScript() && lua_interface && lua_interface->RunItemScriptWithReturnString(item->GetItemScript(), "item_description", item, player, &overrideValueStr))
  7619. packet->setArrayDataByName("description", overrideValueStr.c_str(), i);
  7620. // If no price set in the merchant_inventory table then use the old method
  7621. if (ItemInfo.price_item_id == 0 && ItemInfo.price_item2_id == 0 && ItemInfo.price_coins == 0 && ItemInfo.price_status == 0 && ItemInfo.price_stationcash == 0) {
  7622. sell_price = (int32)(item->sell_price * multiplier);
  7623. packet->setArrayDataByName("price", sell_price, i);
  7624. }
  7625. else {
  7626. int8 count = 0;
  7627. if (ItemInfo.price_item_id != 0 && ItemInfo.price_item_qty != 0)
  7628. count++;
  7629. if (ItemInfo.price_item2_id != 0 && ItemInfo.price_item2_qty != 0)
  7630. count++;
  7631. if (count != 0) {
  7632. packet->setSubArrayLengthByName("num_tokens", count, i);
  7633. int8 index = 0;
  7634. Item* token = 0;
  7635. if (ItemInfo.price_item_id != 0) {
  7636. token = master_item_list.GetItem(ItemInfo.price_item_id);
  7637. if (item) {
  7638. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  7639. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item_qty, i, index);
  7640. packet->setSubArrayDataByName("token_id", ItemInfo.price_item_id, i, index);
  7641. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  7642. }
  7643. token = 0;
  7644. index++;
  7645. }
  7646. if (ItemInfo.price_item2_id != 0) {
  7647. token = master_item_list.GetItem(ItemInfo.price_item2_id);
  7648. if (item) {
  7649. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  7650. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item2_qty, i, index);
  7651. packet->setSubArrayDataByName("token_id", ItemInfo.price_item2_id, i, index);
  7652. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  7653. }
  7654. }
  7655. }
  7656. packet->setArrayDataByName("price", ItemInfo.price_coins, i);
  7657. packet->setArrayDataByName("status2", ItemInfo.price_status, i);
  7658. packet->setArrayDataByName("station_cash", ItemInfo.price_stationcash, i);
  7659. }
  7660. }
  7661. if (GetVersion() < 561) {
  7662. //buy is 0 so dont need to set it
  7663. if (sell)
  7664. packet->setDataByName("type", 1);
  7665. }
  7666. else if (GetVersion() == 561) {
  7667. packet->setDataByName("type", 2);
  7668. }
  7669. else {
  7670. if (sell)
  7671. packet->setDataByName("type", 130);
  7672. else
  7673. packet->setDataByName("type", 2);
  7674. }
  7675. EQ2Packet* outapp = packet->serialize();
  7676. QueuePacket(outapp);
  7677. safe_delete(packet);
  7678. }
  7679. safe_delete(items);
  7680. }
  7681. else {
  7682. // Need to send an empty packet in the event there is no item list, otherwise the
  7683. // last item list sent to the player will show for this merchant
  7684. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7685. if (packet) {
  7686. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7687. if (GetVersion() <= 561) {
  7688. //buy is 0 so dont need to set it
  7689. if (sell)
  7690. packet->setDataByName("type", 1);
  7691. }
  7692. else {
  7693. if (sell)
  7694. packet->setDataByName("type", 130);
  7695. else
  7696. packet->setDataByName("type", 2);
  7697. }
  7698. EQ2Packet* outapp = packet->serialize();
  7699. QueuePacket(outapp);
  7700. safe_delete(packet);
  7701. }
  7702. }
  7703. }
  7704. }
  7705. void Client::SendSellMerchantList(bool sell) {
  7706. Spawn* spawn = GetMerchantTransaction();
  7707. if (!spawn || (spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY) || (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO))
  7708. return;
  7709. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  7710. map<int32, Item*>* items = player->GetItemList();
  7711. if (items) {
  7712. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7713. if (packet) {
  7714. vector<Item*> sellable_items;
  7715. map<int32, Item*>::iterator test_itr;
  7716. for (test_itr = items->begin(); test_itr != items->end(); test_itr++) {
  7717. bool isbagwithitems = false;
  7718. 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))
  7719. isbagwithitems = true;
  7720. 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))
  7721. sellable_items.push_back(test_itr->second);
  7722. }
  7723. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7724. packet->setArrayLengthByName("num_items", sellable_items.size());
  7725. vector<Item*>::iterator itr;
  7726. Item* item = 0;
  7727. sint8 item_difficulty = 0;
  7728. float multiplier = CalculateSellMultiplier(spawn->GetMerchantID());
  7729. int32 sell_price = 0;
  7730. Item* master_item = 0;
  7731. int i = 0;
  7732. int tmp_level = 0;
  7733. for (itr = sellable_items.begin(); itr != sellable_items.end(); itr++, i++) {
  7734. item = *itr;
  7735. master_item = master_item_list.GetItem(item->details.item_id);
  7736. if (master_item)
  7737. sell_price = (int32)(master_item->sell_price * multiplier);
  7738. else
  7739. sell_price = 0;
  7740. if (sell_price > item->sell_price)
  7741. sell_price = item->sell_price;
  7742. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  7743. string thename = item->name;
  7744. packet->setArrayDataByName("price", sell_price, i);
  7745. packet->setArrayDataByName("status", 0, i);//additive to status 2 maybe for server bonus etc
  7746. int8 dispFlags = 0;
  7747. // only city merchants allow selling for status
  7748. if(item->sell_status > 0 && (spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT))
  7749. {
  7750. packet->setArrayDataByName("status2", item->sell_status, i); //this one is the main status
  7751. int32 guildMaxLevel = 5 + item->details.recommended_level; // client hard codes +5 to the level
  7752. if (GetPlayer()->GetGuild() && GetPlayer()->GetGuild()->GetLevel() >= guildMaxLevel) {
  7753. dispFlags += DISPLAY_FLAG_NO_GUILD_STATUS;
  7754. }
  7755. }
  7756. if(item->no_buy_back || (item->sell_status > 0 && (spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))
  7757. {
  7758. if(GetVersion() < 1188)
  7759. 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
  7760. else
  7761. dispFlags += DISPLAY_FLAG_NO_BUYBACK;
  7762. }
  7763. if(item->no_sale)
  7764. dispFlags += DISPLAY_FLAG_NOT_FOR_SALE;
  7765. packet->setArrayDataByName("display_flags", dispFlags, i);
  7766. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7767. packet->setArrayDataByName("unique_item_id", item->details.unique_id, i);
  7768. packet->setArrayDataByName("stack_size", item->details.count, i);
  7769. packet->setArrayDataByName("icon", item->details.icon, i);
  7770. if (item->generic_info.adventure_default_level > 0)
  7771. tmp_level = item->generic_info.adventure_default_level;
  7772. else
  7773. tmp_level = item->generic_info.tradeskill_default_level;
  7774. packet->setArrayDataByName("level", item->details.recommended_level, i);
  7775. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  7776. packet->setArrayDataByName("tier", item->details.tier, i);
  7777. }
  7778. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  7779. item_difficulty = player->GetArrowColor(tmp_level);
  7780. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7781. item_difficulty = ARROW_COLOR_WHITE;
  7782. sint64 overrideValue = 0;
  7783. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "item_difficulty", item, player, nullptr, &overrideValue))
  7784. item_difficulty = (sint8)overrideValue;
  7785. item_difficulty -= 6;
  7786. if (item_difficulty < 0)
  7787. item_difficulty *= -1;
  7788. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7789. if (item->details.count == 1)
  7790. packet->setArrayDataByName("quantity", 0xFFFF, i);
  7791. else
  7792. packet->setArrayDataByName("quantity", item->details.count, i);
  7793. packet->setArrayDataByName("stack_size2", item->details.count, i);
  7794. if (GetVersion() <= 1096)
  7795. packet->setArrayDataByName("description", item->description.c_str(), i);
  7796. }
  7797. if (GetVersion() < 561) {
  7798. packet->setDataByName("type", 1);
  7799. }
  7800. else if(GetVersion() == 561) {
  7801. packet->setDataByName("type", 1);
  7802. }
  7803. else {
  7804. if (sell)
  7805. packet->setDataByName("type", 129);
  7806. else
  7807. packet->setDataByName("type", 1);
  7808. }
  7809. packet->setDataByName("unknown8a", 16256, 6);
  7810. packet->setDataByName("unknown8a", 16256, 10);
  7811. //packet->PrintPacket();
  7812. EQ2Packet* outapp = packet->serialize();
  7813. //DumpPacket(outapp);
  7814. QueuePacket(outapp);
  7815. safe_delete(packet);
  7816. }
  7817. safe_delete(items);
  7818. }
  7819. }
  7820. }
  7821. void Client::SendBuyBackList(bool sell) {
  7822. if (GetVersion() <= 561) //this wasn't added until LU37 on July 31st 2007, well after the DoF client
  7823. return;
  7824. Spawn* spawn = GetMerchantTransaction();
  7825. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  7826. deque<BuyBackItem*>::iterator itr;
  7827. int i = 0;
  7828. Item* master_item = 0;
  7829. BuyBackItem* buyback = 0;
  7830. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7831. if (packet) {
  7832. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7833. packet->setArrayLengthByName("num_items", buy_back_items.size());
  7834. sint8 item_difficulty = 0;
  7835. MBuyBack.readlock(__FUNCTION__, __LINE__);
  7836. int tmp_level = 0;
  7837. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++, i++) {
  7838. buyback = *itr;
  7839. master_item = master_item_list.GetItem(buyback->item_id);
  7840. if (master_item) {
  7841. packet->setArrayDataByName("item_name", master_item->name.c_str(), i);
  7842. packet->setArrayDataByName("price", buyback->price, i);
  7843. packet->setArrayDataByName("item_id", master_item->details.item_id, i);
  7844. packet->setArrayDataByName("unique_item_id", buyback->unique_id, i);
  7845. packet->setArrayDataByName("stack_size", buyback->quantity, i);
  7846. packet->setArrayDataByName("icon", master_item->details.icon, i);
  7847. if (master_item->generic_info.adventure_default_level > 0)
  7848. tmp_level = master_item->generic_info.adventure_default_level;
  7849. else
  7850. tmp_level = master_item->generic_info.tradeskill_default_level;
  7851. packet->setArrayDataByName("level", tmp_level, i);
  7852. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  7853. packet->setArrayDataByName("tier", master_item->details.tier, i);
  7854. }
  7855. packet->setArrayDataByName("item_id2", master_item->details.item_id, i);
  7856. item_difficulty = player->GetArrowColor(tmp_level);
  7857. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7858. item_difficulty = ARROW_COLOR_WHITE;
  7859. sint64 overrideValue = 0;
  7860. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "item_difficulty", master_item, player, nullptr, &overrideValue))
  7861. item_difficulty = (sint8)overrideValue;
  7862. item_difficulty -= 6;
  7863. if (item_difficulty < 0)
  7864. item_difficulty *= -1;
  7865. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7866. sint64 dispFlags = 0;
  7867. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "buyback_display_flags", master_item, player, nullptr, &dispFlags))
  7868. packet->setArrayDataByName("display_flags", (int8)dispFlags, i);
  7869. if (buyback->quantity == 1)
  7870. packet->setArrayDataByName("quantity", 0xFFFF, i);
  7871. else
  7872. packet->setArrayDataByName("quantity", buyback->quantity, i);
  7873. packet->setArrayDataByName("stack_size2", buyback->quantity, i);
  7874. if (GetVersion() <= 1096)
  7875. packet->setArrayDataByName("description", master_item->description.c_str(), i);
  7876. }
  7877. }
  7878. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  7879. if (sell)
  7880. packet->setDataByName("type", 640);
  7881. else
  7882. packet->setDataByName("type", 512);
  7883. EQ2Packet* outapp = packet->serialize();
  7884. // DumpPacket(outapp);
  7885. QueuePacket(outapp);
  7886. safe_delete(packet);
  7887. }
  7888. }
  7889. }
  7890. void Client::SendRepairList() {
  7891. Spawn* spawn = GetMerchantTransaction();
  7892. if (spawn) {
  7893. vector<Item*>* repairable_items = GetRepairableItems();
  7894. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7895. if (packet) {
  7896. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7897. packet->setArrayLengthByName("num_items", repairable_items->size());
  7898. Item* item = 0;
  7899. sint8 item_difficulty = 0;
  7900. int32 i = 0;
  7901. vector<Item*>::iterator itr;
  7902. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++, i++) {
  7903. item = *itr;
  7904. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  7905. packet->setArrayDataByName("price", item->CalculateRepairCost(), i);
  7906. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7907. packet->setArrayDataByName("stack_size", item->details.count, i);
  7908. packet->setArrayDataByName("icon", item->details.icon, i);
  7909. /*if (item->generic_info.adventure_default_level > 0)
  7910. tmp_level = item->generic_info.adventure_default_level;
  7911. else
  7912. tmp_level = item->generic_info.tradeskill_default_level;
  7913. packet->setArrayDataByName("level", tmp_level, i);*/
  7914. packet->setArrayDataByName("level", item->generic_info.adventure_default_level, i);
  7915. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  7916. packet->setArrayDataByName("tier", item->details.tier, i);
  7917. }
  7918. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  7919. item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  7920. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7921. item_difficulty = ARROW_COLOR_WHITE;
  7922. item_difficulty -= 6;
  7923. if (item_difficulty < 0)
  7924. item_difficulty *= -1;
  7925. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7926. if (item->details.count == 1)
  7927. packet->setArrayDataByName("quantity", 0xFFFF, i);
  7928. else
  7929. packet->setArrayDataByName("quantity", item->details.count, i);
  7930. packet->setArrayDataByName("stack_size2", item->details.count, i);
  7931. if (GetVersion() <= 1096)
  7932. packet->setArrayDataByName("description", item->description.c_str(), i);
  7933. }
  7934. if (GetVersion() <= 561) {
  7935. packet->setDataByName("type", 112);
  7936. }
  7937. else {
  7938. packet->setDataByName("type", 96);
  7939. }
  7940. EQ2Packet* outapp = packet->serialize();
  7941. //DumpPacket(outapp);
  7942. QueuePacket(outapp);
  7943. /*if (GetVersion() <= 561) {
  7944. packet->setDataByName("type", 16);
  7945. EQ2Packet* outapp2 = packet->serialize();
  7946. QueuePacket(outapp2);
  7947. }*/
  7948. safe_delete(packet);
  7949. }
  7950. safe_delete(repairable_items);
  7951. }
  7952. }
  7953. void Client::ShowLottoWindow() {
  7954. if(GetVersion() <= 373) {
  7955. SimpleMessage(CHANNEL_COLOR_RED, "This client does not support the gambler UI, only Desert of Flames or later client.");
  7956. return;
  7957. }
  7958. Spawn* spawn = GetMerchantTransaction();
  7959. if (spawn) {
  7960. int32 item_id = rule_manager.GetGlobalRule(R_World, GamblingTokenItemID)->GetInt32();
  7961. if (!item_id)
  7962. {
  7963. LogWrite(WORLD__ERROR, 0, "World", "No GamblingTokenItemID rule set!");
  7964. SimpleMessage(CHANNEL_COLOR_RED, "The server admin has not setup a lotto item ticket.");
  7965. return;
  7966. }
  7967. else if (item_id == 0)
  7968. {
  7969. LogWrite(WORLD__ERROR, 0, "World", "Error! Invalid GamblingTokenItemID value!");
  7970. return;
  7971. }
  7972. Item* item = master_item_list.GetItem(item_id);
  7973. if (!item) {
  7974. LogWrite(WORLD__ERROR, 0, "World", "The 'GamblingTokenItemID' rule value %u is not a valid item id.", item_id);
  7975. return;
  7976. }
  7977. LogWrite(WORLD__DEBUG, 0, "World", "GamblingTokenItemID = '%s' (%u)", item->name.c_str(), item_id);
  7978. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7979. if (packet) {
  7980. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7981. packet->setArrayLengthByName("num_items", 1);
  7982. packet->setArrayDataByName("item_name", item->name.c_str());
  7983. packet->setArrayDataByName("price", item->sell_price);
  7984. packet->setArrayDataByName("item_id", item->details.item_id);
  7985. packet->setArrayDataByName("stack_size", item->details.count);
  7986. packet->setArrayDataByName("icon", item->details.icon);
  7987. packet->setArrayDataByName("level", item->generic_info.adventure_default_level);
  7988. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  7989. packet->setArrayDataByName("tier", item->details.tier);
  7990. }
  7991. packet->setArrayDataByName("item_id2", item->details.item_id);
  7992. int8 item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  7993. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7994. item_difficulty = ARROW_COLOR_WHITE;
  7995. item_difficulty -= 6;
  7996. if (item_difficulty < 0)
  7997. item_difficulty *= -1;
  7998. packet->setArrayDataByName("item_difficulty", item_difficulty);
  7999. //if(item->details.count == 1)
  8000. packet->setArrayDataByName("quantity", 0xFFFF);
  8001. //else
  8002. // packet->setArrayDataByName("quantity", item->details.count);
  8003. packet->setArrayDataByName("stack_size2", item->details.count);
  8004. packet->setArrayDataByName("description", item->description.c_str());
  8005. if (GetVersion() <= 546) {
  8006. packet->setDataByName("type", 128);
  8007. }
  8008. else {
  8009. packet->setDataByName("type", 0x00000102);
  8010. }
  8011. QueuePacket(packet->serialize());
  8012. safe_delete(packet);
  8013. }
  8014. }
  8015. }
  8016. void Client::PlayLotto(int32 price, int32 ticket_item_id) {
  8017. PacketStruct* packet = configReader.getStruct("WS_Lottery", GetVersion());
  8018. if (packet) {
  8019. world.AddLottoPlayer(GetCharacterID(), Timer::GetCurrentTime2() + 4500);
  8020. int32 rolls[6] = { 0 };
  8021. int32 lottery_digits[6] = { 0 };
  8022. int8 num_matches = 0;
  8023. int64 jackpot = 0;
  8024. Item* item = GetPlayer()->item_list.GetItemFromID(ticket_item_id);
  8025. if (!item) {
  8026. return;
  8027. }
  8028. database.DeleteItem(GetCharacterID(), item, 0);
  8029. GetPlayer()->item_list.RemoveItem(item, true);
  8030. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  8031. Variable* winning_numbers = variables.FindVariable("gambling_winning_numbers");
  8032. if (!winning_numbers) {
  8033. winning_numbers = new Variable("gambling_winning_numbers", "231205182236", "Current Gigglegibber Gambling Game winning numbers");
  8034. variables.AddVariable(winning_numbers);
  8035. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  8036. }
  8037. if (strlen(winning_numbers->GetValue()) != 12) {
  8038. winning_numbers->SetValue("231205182236");
  8039. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  8040. }
  8041. try {
  8042. for (int32 i = 0; i < 12; i += 2) {
  8043. char num[4];
  8044. strncpy(num, winning_numbers->GetValue() + i, 2);
  8045. lottery_digits[i / 2] = atoi(num);
  8046. }
  8047. }
  8048. catch (...) {
  8049. LogWrite(WORLD__ERROR, 0, "World", "Error parsing 'gambling_winning_numbers' variable");
  8050. return;
  8051. }
  8052. Variable* jackpot_var = variables.FindVariable("gambling_current_jackpot");
  8053. if (!jackpot_var) {
  8054. jackpot_var = new Variable("gambling_current_jackpot", "10000", "Current Gigglegibber Gambling Game Jackpot");
  8055. variables.AddVariable(jackpot_var);
  8056. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  8057. }
  8058. try {
  8059. jackpot = atoul(jackpot_var->GetValue());
  8060. if (jackpot < 10000)
  8061. jackpot = 10000;
  8062. }
  8063. catch (...) {
  8064. jackpot = 10000;
  8065. }
  8066. char new_jackpot[128] = { 0 };
  8067. sprintf(new_jackpot, "%llu", jackpot + price);
  8068. jackpot_var->SetValue(new_jackpot);
  8069. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  8070. world.PickRandomLottoDigits(rolls);
  8071. packet->setDataByName("roll_digit1", rolls[0]);
  8072. packet->setDataByName("roll_digit2", rolls[1]);
  8073. packet->setDataByName("roll_digit3", rolls[2]);
  8074. packet->setDataByName("roll_digit4", rolls[3]);
  8075. packet->setDataByName("roll_digit5", rolls[4]);
  8076. packet->setDataByName("roll_digit6", rolls[5]);
  8077. packet->setDataByName("lottery_digit1", lottery_digits[0]);
  8078. packet->setDataByName("lottery_digit2", lottery_digits[1]);
  8079. packet->setDataByName("lottery_digit3", lottery_digits[2]);
  8080. packet->setDataByName("lottery_digit4", lottery_digits[3]);
  8081. packet->setDataByName("lottery_digit5", lottery_digits[4]);
  8082. packet->setDataByName("lottery_digit6", lottery_digits[5]);
  8083. QueuePacket(packet->serialize());
  8084. safe_delete(packet);
  8085. for (int32 i = 0; i < 6; i++) {
  8086. for (int32 j = 0; j < 6; j++) {
  8087. if (rolls[i] == lottery_digits[j]) {
  8088. num_matches++;
  8089. break;
  8090. }
  8091. }
  8092. }
  8093. char new_jackpot_str[16];
  8094. memset(new_jackpot_str, 0, sizeof(new_jackpot_str));
  8095. world.SetLottoPlayerNumMatches(GetCharacterID(), num_matches);
  8096. if (num_matches == 6) {
  8097. world.PickRandomLottoDigits(lottery_digits);
  8098. for (int32 i = 0; i < 12; i += 2)
  8099. sprintf(new_jackpot_str + i, "%02d", lottery_digits[i / 2]);
  8100. winning_numbers->SetValue(new_jackpot_str);
  8101. jackpot_var->SetValue("10000");
  8102. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  8103. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  8104. }
  8105. }
  8106. }
  8107. void Client::SendGuildCreateWindow() {
  8108. if (GetVersion() <= 561) {
  8109. SimpleMessage(0, "Not implemented on this client...yet?");
  8110. }
  8111. else {
  8112. Spawn* spawn = GetPlayer()->GetTarget();
  8113. if (spawn) {
  8114. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  8115. if (packet) {
  8116. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  8117. packet->setArrayLengthByName("num_items", 0);
  8118. packet->setDataByName("type", 0x00008000);
  8119. QueuePacket(packet->serialize());
  8120. safe_delete(packet);
  8121. }
  8122. }
  8123. }
  8124. }
  8125. void Client::AddBuyBack(int32 unique_id, int32 item_id, int16 quantity, int32 price, bool save_needed) {
  8126. BuyBackItem* item = new BuyBackItem;
  8127. item->item_id = item_id;
  8128. item->unique_id = unique_id;
  8129. item->price = price;
  8130. item->quantity = quantity;
  8131. item->save_needed = save_needed;
  8132. MBuyBack.writelock(__FUNCTION__, __LINE__);
  8133. buy_back_items.push_back(item);
  8134. if (buy_back_items.size() > 10) {
  8135. safe_delete(buy_back_items.front());
  8136. buy_back_items.pop_front();
  8137. }
  8138. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  8139. }
  8140. deque<BuyBackItem*>* Client::GetBuyBacks() {
  8141. return &buy_back_items;
  8142. }
  8143. vector<Item*>* Client::GetRepairableItems() {
  8144. vector<Item*>* repairable_items = new vector<Item*>;
  8145. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  8146. map<int32, Item*>* items = player->GetItemList();
  8147. if (equipped_items && equipped_items->size() > 0) {
  8148. for (int32 i = 0; i < equipped_items->size(); i++) {
  8149. Item* item = equipped_items->at(i);
  8150. if (item && !item->CheckFlag2(NO_REPAIR) && item->generic_info.condition < 100)
  8151. repairable_items->push_back(item);
  8152. }
  8153. }
  8154. if (items && items->size() > 0) {
  8155. map<int32, Item*>::iterator itr;
  8156. for (itr = items->begin(); itr != items->end(); itr++) {
  8157. Item* item = itr->second;
  8158. if (item && !item->CheckFlag2(NO_REPAIR) && item->generic_info.condition < 100)
  8159. repairable_items->push_back(item);
  8160. }
  8161. }
  8162. safe_delete(equipped_items);
  8163. safe_delete(items);
  8164. return repairable_items;
  8165. }
  8166. vector<Item*>* Client::GetItemsByEffectType(ItemEffectType type, ItemEffectType type2) {
  8167. if(type == NO_EFFECT_TYPE)
  8168. return nullptr;
  8169. vector<Item*>* return_items = new vector<Item*>;
  8170. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  8171. map<int32, Item*>* items = player->GetItemList();
  8172. if (equipped_items && equipped_items->size() > 0) {
  8173. for (int32 i = 0; i < equipped_items->size(); i++) {
  8174. Item* item = equipped_items->at(i);
  8175. if (item && (item->effect_type == type || (type2 != NO_EFFECT_TYPE && item->effect_type == type2)))
  8176. return_items->push_back(item);
  8177. }
  8178. }
  8179. if (items && items->size() > 0) {
  8180. map<int32, Item*>::iterator itr;
  8181. for (itr = items->begin(); itr != items->end(); itr++) {
  8182. Item* item = itr->second;
  8183. if (item && (item->effect_type == type || (type2 != NO_EFFECT_TYPE && item->effect_type == type2)))
  8184. return_items->push_back(item);
  8185. }
  8186. }
  8187. safe_delete(equipped_items);
  8188. safe_delete(items);
  8189. return return_items;
  8190. }
  8191. void Client::SendMailList() {
  8192. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  8193. if (kiosk_id > 0) {
  8194. PacketStruct* p = configReader.getStruct("WS_GetMailHeader", GetVersion());
  8195. if (p) {
  8196. MutexMap<int32, Mail*>* mail_list = player->GetMail();
  8197. MutexMap<int32, Mail*>::iterator itr = mail_list->begin();
  8198. int32 i = 0;
  8199. p->setDataByName("kiosk_id", kiosk_id);
  8200. p->setArrayLengthByName("num_messages", (int16)mail_list->size());
  8201. while (itr.Next()) {
  8202. Mail* mail = itr->second;
  8203. p->setArrayDataByName("mail_id", mail->mail_id, i);
  8204. p->setArrayDataByName("player_to_id", mail->player_to_id, i);
  8205. p->setArrayDataByName("player_from", mail->player_from.c_str(), i);
  8206. p->setArrayDataByName("subject", mail->subject.c_str(), i);
  8207. p->setArrayDataByName("already_read", mail->already_read, i);
  8208. if(mail->expire_time)
  8209. p->setArrayDataByName("mail_deletion", mail->expire_time - mail->time_sent, i);
  8210. else
  8211. p->setArrayDataByName("mail_deletion", 0, i);
  8212. p->setArrayDataByName("mail_type", mail->mail_type, i);
  8213. p->setArrayDataByName("mail_expire", 0xFFFFFFFF, i);
  8214. p->setArrayDataByName("unknown1a", 0xFFFFFFFF, i);
  8215. p->setArrayDataByName("coin_copper", mail->coin_copper, i);
  8216. p->setArrayDataByName("coin_silver", mail->coin_silver, i);
  8217. p->setArrayDataByName("coin_gold", mail->coin_gold, i);
  8218. p->setArrayDataByName("coin_plat", mail->coin_plat, i);
  8219. //p->setArrayDataByName("unknown2", 0, i);
  8220. bool successItemAdd = false;
  8221. if(mail->stack || mail->char_item_id)
  8222. {
  8223. Item* item = master_item_list.GetItem(mail->char_item_id);
  8224. if(item)
  8225. {
  8226. item->stack_count = mail->stack > 1 ? mail->stack : 0;
  8227. if (version < 860)
  8228. p->setItemArrayDataByName("item", item, player, i, 0, GetClientItemPacketOffset());
  8229. else if (version < 1193)
  8230. p->setItemArrayDataByName("item", item, player, i);
  8231. else
  8232. p->setItemArrayDataByName("item", item, player, i, 0, 2);
  8233. successItemAdd = true;
  8234. }
  8235. }
  8236. if(!successItemAdd)
  8237. {
  8238. p->setArrayDataByName("end_tag2", GetItemPacketType(GetVersion()), i);
  8239. p->setArrayDataByName("end_tag3", 0xFF, i);
  8240. }
  8241. i++;
  8242. }
  8243. // GMs send mail for free!
  8244. if (GetAdminStatus() > 0)
  8245. {
  8246. p->setDataByName("postage_cost", 0);
  8247. p->setDataByName("attachment_cost", 0);
  8248. }
  8249. else
  8250. {
  8251. p->setDataByName("postage_cost", 10);
  8252. p->setDataByName("attachment_cost", 50);
  8253. }
  8254. p->setDataByName("unknown3", 0x01F4);
  8255. p->setDataByName("unknown4", 0x01000000);
  8256. EQ2Packet* pack = p->serialize();
  8257. //DumpPacket(pack);
  8258. QueuePacket(pack);
  8259. safe_delete(p);
  8260. }
  8261. }
  8262. else
  8263. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8264. }
  8265. void Client::DisplayMailMessage(int32 mail_id) {
  8266. Mail* mail = player->GetMail(mail_id);
  8267. if (mail) {
  8268. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  8269. if (kiosk_id > 0) {
  8270. PacketStruct* update = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8271. if (update) {
  8272. update->setDataByName("action", 0x03);
  8273. update->setDataByName("packettype", GetItemPacketType(GetVersion()));
  8274. update->setDataByName("packetsubtype", 0xFF);
  8275. QueuePacket(update->serialize());
  8276. safe_delete(update);
  8277. }
  8278. if(!mail->already_read) {
  8279. mail->already_read = true;
  8280. SendMailList();
  8281. }
  8282. PacketStruct* packet = configReader.getStruct("WS_MailGetMessage", GetVersion());
  8283. if (packet) {
  8284. packet->setDataByName("kiosk_id", kiosk_id);
  8285. packet->setDataByName("mail_id", mail->mail_id);
  8286. packet->setDataByName("player_to_id", mail->player_to_id);
  8287. packet->setDataByName("player_from", mail->player_from.c_str());
  8288. packet->setDataByName("subject", mail->subject.c_str());
  8289. packet->setDataByName("mail_body", mail->mail_body.c_str());
  8290. packet->setDataByName("unknown1", 1);
  8291. packet->setDataByName("unknown2", 0);
  8292. packet->setDataByName("lock_report_button", 1);
  8293. packet->setDataByName("unknown3", 0xFFFFFFFF);
  8294. packet->setDataByName("unknown3a", 0xFFFFFFFF);
  8295. packet->setDataByName("coin_copper", mail->coin_copper);
  8296. packet->setDataByName("coin_silver", mail->coin_silver);
  8297. packet->setDataByName("coin_gold", mail->coin_gold);
  8298. packet->setDataByName("coin_plat", mail->coin_plat);
  8299. if(mail->stack || mail->char_item_id)
  8300. {
  8301. Item* item = master_item_list.GetItem(mail->char_item_id);
  8302. item->stack_count = mail->stack > 1 ? mail->stack : 0;
  8303. if (version < 860)
  8304. packet->setItemByName("item", item, player, 0, version <= 373 ? -2 : -1);
  8305. else if (version < 1193)
  8306. packet->setItemByName("item", item, player, 0, 0);
  8307. else
  8308. packet->setItemByName("item", item, player, 0, 2);
  8309. }
  8310. else
  8311. {
  8312. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  8313. packet->setDataByName("end_tag3", 0xFF);
  8314. }
  8315. mail->save_needed = true;
  8316. EQ2Packet* pack = packet->serialize();
  8317. QueuePacket(pack);
  8318. safe_delete(packet);
  8319. // trying to update this causes the window not to open
  8320. //SendMailList();
  8321. }
  8322. }
  8323. else
  8324. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8325. }
  8326. }
  8327. /* 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
  8328. packet back to the client before the mail actually sent. */
  8329. void Client::HandleSentMail(EQApplicationPacket* app) {
  8330. PacketStruct* packet = configReader.getStruct("WS_MailSendMessage", GetVersion());
  8331. if (packet) {
  8332. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  8333. string player_to = packet->getType_EQ2_16BitString_ByName("player_to").data;
  8334. PacketStruct* reply_packet = configReader.getStruct("WS_MailSendMessageReply", GetVersion());
  8335. vector<int32>* ids = 0;
  8336. MMailWindowMutex.lock();
  8337. if (reply_packet) {
  8338. int8 reply_type = MAIL_SEND_RESULT_UNKNOWN_ERROR;
  8339. if (player_to.length() == 0)
  8340. reply_type = MAIL_SEND_RESULT_EMPTY_TO_LIST;
  8341. else if (player_to.compare(string(GetPlayer()->GetName())) == 0)
  8342. reply_type = MAIL_SEND_RESULT_CANNOT_SEND_TO_SELF;
  8343. else if (GetAdminStatus() == 0 && !player->RemoveCoins(10))
  8344. reply_type = MAIL_SEND_RESULT_NOT_ENOUGH_COIN;
  8345. else {
  8346. if (GetAdminStatus() > 200 && player_to.compare("<all>") == 0) {
  8347. if (mail_window.char_item_id == 0 && (mail_window.coin_copper + mail_window.coin_silver + mail_window.coin_gold + mail_window.coin_plat) == 0)
  8348. ids = database.GetAllPlayerIDs();
  8349. else
  8350. SimpleMessage(CHANNEL_NARRATIVE, "You may not mail gifts to multiple players.");
  8351. }
  8352. else {
  8353. ids = new vector<int32>;
  8354. ids->push_back(database.GetCharacterID(player_to.c_str()));
  8355. }
  8356. if (ids) {
  8357. for (int32 i = 0; i < ids->size(); i++) {
  8358. int32 player_to_id = ids->at(i);
  8359. if (player_to_id > 0) {
  8360. reply_type = MAIL_SEND_RESULT_SUCCESS;
  8361. Mail* mail = new Mail;
  8362. mail->mail_id = 0;
  8363. mail->player_to_id = player_to_id;
  8364. mail->player_from = string(GetPlayer()->GetName());
  8365. mail->subject = packet->getType_EQ2_16BitString_ByName("subject").data;
  8366. mail->mail_body = packet->getType_EQ2_16BitString_ByName("mail_body").data;
  8367. mail->already_read = 0;
  8368. mail->mail_type = MAIL_TYPE_REGULAR;
  8369. mail->coin_copper = mail_window.coin_copper;
  8370. mail->coin_silver = mail_window.coin_silver;
  8371. mail->coin_gold = mail_window.coin_gold;
  8372. mail->coin_plat = mail_window.coin_plat;
  8373. mail->char_item_id = mail_window.char_item_id;
  8374. mail->stack = mail_window.stack;
  8375. // GM's send mail for free!
  8376. if (GetAdminStatus() > 0)
  8377. {
  8378. mail->postage_cost = 0;
  8379. mail->attachment_cost = 0;
  8380. }
  8381. else
  8382. {
  8383. mail->postage_cost = 10;
  8384. mail->attachment_cost = 50;
  8385. }
  8386. mail->time_sent = Timer::GetUnixTimeStamp();
  8387. mail->expire_time = mail->time_sent + 2592000; //30 days in seconds
  8388. mail->save_needed = false;
  8389. database.SavePlayerMail(mail);
  8390. Client* to_client = zone_list.GetClientByCharID(player_to_id);
  8391. if (to_client) {
  8392. to_client->GetPlayer()->AddMail(mail);
  8393. to_client->SimpleMessage(CHANNEL_NARRATIVE, "You have unread mail in your mailbox.");
  8394. string popup_text = "You have unread mail!";
  8395. to_client->SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  8396. }
  8397. else {
  8398. // don't need the pointer the client doesn't exist currently
  8399. safe_delete(mail);
  8400. }
  8401. ResetSendMail(false, false);
  8402. }
  8403. else
  8404. reply_type = MAIL_SEND_RESULT_UNKNOWN_PLAYER;
  8405. }
  8406. }
  8407. }
  8408. string players_to = "";
  8409. if (ids) {
  8410. for (int32 i = 0; i < ids->size(); i++) {
  8411. if (ids->at(i) != 0)
  8412. players_to.append(database.GetCharacterName(ids->at(i)));
  8413. if (i < (ids->size() - 1))
  8414. players_to.append(", ");
  8415. }
  8416. }
  8417. reply_packet->setDataByName("player_to", players_to.c_str());
  8418. reply_packet->setDataByName("reply_type", reply_type);
  8419. QueuePacket(reply_packet->serialize());
  8420. safe_delete(reply_packet);
  8421. safe_delete(ids);
  8422. }
  8423. MMailWindowMutex.unlock();
  8424. }
  8425. safe_delete(packet);
  8426. }
  8427. }
  8428. void Client::DeleteMail(int32 mail_id, bool from_database) {
  8429. player->DeleteMail(mail_id, from_database);
  8430. }
  8431. bool Client::AddMailItem(Item* item)
  8432. {
  8433. if(item && (item->CheckFlag(LORE) || item->CheckFlag(STACK_LORE))) {
  8434. Message(CHANNEL_COLOR_CHAT_RELATIONSHIP, "Lore items cannot be mailed.");
  8435. return false;
  8436. }
  8437. bool ret = false;
  8438. if (GetMailTransaction()) {
  8439. MMailWindowMutex.lock();
  8440. if(mail_window.char_item_id == 0)
  8441. {
  8442. mail_window.item = item;
  8443. mail_window.char_item_id = item->details.item_id;
  8444. mail_window.stack = item->details.count;
  8445. ret = true;
  8446. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8447. packet->setDataByName("coin_copper", mail_window.coin_copper);
  8448. packet->setDataByName("coin_silver", mail_window.coin_silver);
  8449. packet->setDataByName("coin_gold", mail_window.coin_gold);
  8450. packet->setDataByName("coin_plat", mail_window.coin_plat);
  8451. if(item)
  8452. {
  8453. packet->setDataByName("stack", mail_window.stack);
  8454. item->stack_count = mail_window.stack;
  8455. if (version < 860)
  8456. packet->setItemByName("item", item, player, 0, version <= 373 ? -2 : -1);
  8457. else if (version < 1193)
  8458. packet->setItemByName("item", item, player, 0, 0);
  8459. else
  8460. packet->setItemByName("item", item, player, 0, 2);
  8461. }
  8462. else
  8463. {
  8464. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  8465. packet->setDataByName("end_tag3", 0xFF);
  8466. }
  8467. QueuePacket(packet->serialize());
  8468. }
  8469. MMailWindowMutex.unlock();
  8470. }
  8471. return ret;
  8472. }
  8473. bool Client::AddMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  8474. bool ret = false;
  8475. if (GetMailTransaction()) {
  8476. MMailWindowMutex.lock();
  8477. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8478. if (packet) {
  8479. if (copper > 0) {
  8480. if (player->RemoveCoins(copper)) {
  8481. mail_window.coin_copper += copper;
  8482. Message(CHANNEL_NARRATIVE, "You add %u copper to the mail window.", copper);
  8483. ret = true;
  8484. }
  8485. }
  8486. else if (silver > 0) {
  8487. if (player->RemoveCoins(silver * 100)) {
  8488. mail_window.coin_silver += silver;
  8489. Message(CHANNEL_NARRATIVE, "You add %u silver to the mail window.", silver);
  8490. ret = true;
  8491. }
  8492. }
  8493. else if (gold > 0) {
  8494. if (player->RemoveCoins(gold * 10000)) {
  8495. mail_window.coin_gold += gold;
  8496. Message(CHANNEL_NARRATIVE, "You add %u gold to the mail window.", gold);
  8497. ret = true;
  8498. }
  8499. }
  8500. else if (plat > 0) {
  8501. if (player->RemoveCoins(plat * 1000000)) {
  8502. mail_window.coin_plat += plat;
  8503. Message(CHANNEL_NARRATIVE, "You add %u platinum to the mail window.", plat);
  8504. ret = true;
  8505. }
  8506. }
  8507. if (ret) {
  8508. packet->setDataByName("coin_copper", mail_window.coin_copper);
  8509. packet->setDataByName("coin_silver", mail_window.coin_silver);
  8510. packet->setDataByName("coin_gold", mail_window.coin_gold);
  8511. packet->setDataByName("coin_plat", mail_window.coin_plat);
  8512. Item* item = master_item_list.GetItem(mail_window.char_item_id);
  8513. if(item)
  8514. {
  8515. packet->setDataByName("stack", mail_window.stack);
  8516. item->stack_count = mail_window.stack;
  8517. if (version < 860)
  8518. packet->setItemByName("item", item, player, 0, version <= 373 ? -2 : -1);
  8519. else if (version < 1193)
  8520. packet->setItemByName("item", item, player, 0, 0);
  8521. else
  8522. packet->setItemByName("item", item, player, 0, 2);
  8523. }
  8524. else
  8525. {
  8526. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  8527. packet->setDataByName("end_tag3", 0xFF);
  8528. }
  8529. //packet->PrintPacket();
  8530. QueuePacket(packet->serialize());
  8531. }
  8532. else
  8533. SimpleMessage(CHANNEL_NARRATIVE, "You don't have that much money.");
  8534. safe_delete(packet);
  8535. }
  8536. MMailWindowMutex.unlock();
  8537. }
  8538. else
  8539. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8540. return ret;
  8541. }
  8542. bool Client::RemoveMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  8543. bool ret = false;
  8544. if (GetMailTransaction()) {
  8545. MMailWindowMutex.lock();
  8546. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8547. if (packet) {
  8548. if (copper > 0) {
  8549. player->AddCoins(copper);
  8550. mail_window.coin_copper -= copper;
  8551. Message(CHANNEL_NARRATIVE, "You remove %u copper from the mail window.", copper);
  8552. ret = true;
  8553. }
  8554. else if (silver > 0) {
  8555. player->AddCoins(silver * 100);
  8556. mail_window.coin_silver -= silver;
  8557. Message(CHANNEL_NARRATIVE, "You remove %u silver from the mail window.", silver);
  8558. ret = true;
  8559. }
  8560. else if (gold > 0) {
  8561. player->AddCoins(gold * 10000);
  8562. mail_window.coin_gold -= gold;
  8563. Message(CHANNEL_NARRATIVE, "You remove %u gold from the mail window.", gold);
  8564. ret = true;
  8565. }
  8566. else if (plat > 0) {
  8567. player->AddCoins(plat * 1000000);
  8568. mail_window.coin_plat -= plat;
  8569. Message(CHANNEL_NARRATIVE, "You remove %u platinum from the mail window.", plat);
  8570. ret = true;
  8571. }
  8572. if (ret) {
  8573. packet->setDataByName("coin_copper", mail_window.coin_copper);
  8574. packet->setDataByName("coin_silver", mail_window.coin_silver);
  8575. packet->setDataByName("coin_gold", mail_window.coin_gold);
  8576. packet->setDataByName("coin_plat", mail_window.coin_plat);
  8577. packet->setDataByName("stack", 0);
  8578. packet->setDataByName("packettype", 0x2BFE);
  8579. packet->setDataByName("packetsubtype", 0xFF);
  8580. packet->setDataByName("unknown2", 0);
  8581. QueuePacket(packet->serialize());
  8582. }
  8583. safe_delete(packet);
  8584. }
  8585. MMailWindowMutex.unlock();
  8586. }
  8587. else
  8588. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8589. return ret;
  8590. }
  8591. void Client::TakeMailAttachments(int32 mail_id) {
  8592. if (GetMailTransaction()) {
  8593. Mail* mail = player->GetMail(mail_id);
  8594. if (mail) {
  8595. int64 amount = 0;
  8596. if (mail->coin_copper > 0) {
  8597. amount += mail->coin_copper;
  8598. mail->coin_copper = 0;
  8599. }
  8600. if (mail->coin_silver > 0) {
  8601. amount += mail->coin_silver * 100;
  8602. mail->coin_silver = 0;
  8603. }
  8604. if (mail->coin_gold > 0) {
  8605. amount += mail->coin_gold * 10000;
  8606. mail->coin_gold = 0;
  8607. }
  8608. if (mail->coin_plat > 0) {
  8609. amount += mail->coin_plat * 1000000;
  8610. mail->coin_plat = 0;
  8611. }
  8612. if (mail->char_item_id > 0) {
  8613. AddItem(mail->char_item_id, mail->stack);
  8614. mail->char_item_id = 0;
  8615. mail->stack = 0;
  8616. }
  8617. /* 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
  8618. the mail the player is getting attachments from. There is an opcode OP_MailRemoveAttachFromMailMsg with opcode 328 but i can't
  8619. find it in any packet logs.*/
  8620. /*PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8621. if (packet) {
  8622. packet->setDataByName("unknown", 0x03);
  8623. packet->setDataByName("coin_copper", mail->coin_copper);
  8624. packet->setDataByName("coin_silver", mail->coin_silver);
  8625. packet->setDataByName("coin_gold", mail->coin_gold);
  8626. packet->setDataByName("coin_plat", mail->coin_plat);
  8627. packet->setDataByName("stack", 0);
  8628. packet->setDataByName("packettype", 0x2BFE);
  8629. packet->setDataByName("packetsubtype", 0xFF);
  8630. packet->setDataByName("unknown2", 0);
  8631. packet->setDataByName("unknown3", 0x00000001);//0x00000016
  8632. DumpPacket(packet->serialize());
  8633. QueuePacket(packet->serialize());
  8634. safe_delete(packet);
  8635. }*/
  8636. database.SavePlayerMail(mail);
  8637. if (amount > 0)
  8638. player->AddCoins(amount);
  8639. SendMailList();
  8640. }
  8641. }
  8642. else
  8643. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8644. }
  8645. void Client::ResetSendMail(bool cancel, bool needslock) {
  8646. if(cancel && mail_transaction)
  8647. SimpleMessage(CHANNEL_NARRATIVE, "You cancel sending a letter.");
  8648. if(needslock)
  8649. MMailWindowMutex.lock();
  8650. if(cancel)
  8651. player->AddCoins(mail_window.coin_copper + (mail_window.coin_silver * 100) + (mail_window.coin_gold * 10000) + (mail_window.coin_plat * 1000000));
  8652. if(!cancel)
  8653. mail_transaction = 0;
  8654. mail_window.coin_copper = 0;
  8655. mail_window.coin_silver = 0;
  8656. mail_window.coin_gold = 0;
  8657. mail_window.coin_plat = 0;
  8658. mail_window.char_item_id = 0;
  8659. mail_window.stack = 0;
  8660. if(mail_window.item){
  8661. if(cancel)
  8662. AddItem(mail_window.item);
  8663. else
  8664. safe_delete(mail_window.item);
  8665. }
  8666. mail_window.item = nullptr;
  8667. if(needslock)
  8668. MMailWindowMutex.unlock();
  8669. }
  8670. bool Client::GateAllowed() {
  8671. ZoneServer* zone = GetCurrentZone();
  8672. if (zone){
  8673. bool cangate = zone->GetCanGate();
  8674. return cangate;
  8675. }
  8676. return false;
  8677. }
  8678. bool Client::BindAllowed() {
  8679. ZoneServer* zone = GetCurrentZone();
  8680. if (zone){
  8681. bool canbind = zone->GetCanBind();
  8682. return canbind;
  8683. }
  8684. return false;
  8685. }
  8686. bool Client::Bind() {
  8687. int canbind = BindAllowed();
  8688. if(canbind == 0) {
  8689. Message(CHANNEL_MERCHANT, "You cannot bind at this location.");
  8690. return false;
  8691. }
  8692. player->GetPlayerInfo()->SetBindZone(GetCurrentZone()->GetZoneID());
  8693. player->GetPlayerInfo()->SetBindX(player->GetX());
  8694. player->GetPlayerInfo()->SetBindY(player->GetY());
  8695. player->GetPlayerInfo()->SetBindZ(player->GetZ());
  8696. player->GetPlayerInfo()->SetBindHeading(player->GetHeading());
  8697. Message(CHANNEL_MERCHANT, "Your spirit has been bound to this location.");
  8698. return true;
  8699. }
  8700. bool Client::Gate(bool is_spell) {
  8701. if (player->GetPlayerInfo()->GetBindZoneID() == 0) {
  8702. SimpleMessage(CHANNEL_MERCHANT, "You can not cast recall spells. You have no bind location set.");
  8703. return false;
  8704. }
  8705. ZoneServer* zone = zone_list.Get(player->GetPlayerInfo()->GetBindZoneID());
  8706. if (zone) {
  8707. int cangate = GateAllowed();
  8708. if(cangate == 0) {
  8709. SimpleMessage(CHANNEL_MERCHANT, "You can not cast recall spells in this zone.");
  8710. return false;
  8711. }
  8712. player->SetX(player->GetPlayerInfo()->GetBindZoneX());
  8713. player->SetY(player->GetPlayerInfo()->GetBindZoneY());
  8714. player->SetZ(player->GetPlayerInfo()->GetBindZoneZ());
  8715. player->SetHeading(player->GetPlayerInfo()->GetBindZoneHeading());
  8716. Zone(zone, false, is_spell);
  8717. return true;
  8718. }
  8719. return false;
  8720. }
  8721. void Client::ProcessTeleport(Spawn* spawn, vector<TransportDestination*>* destinations, int32 transport_id, bool is_spell) {
  8722. if (!destinations || !spawn) {
  8723. return;
  8724. }
  8725. bool has_map = false;
  8726. if (transport_id > 0)
  8727. has_map = GetCurrentZone()->TransportHasMap(transport_id);
  8728. transport_spawn = spawn;
  8729. vector<TransportDestination*> transport_list;
  8730. vector<TransportDestination*>::iterator itr;
  8731. TransportDestination* destination = 0;
  8732. for (itr = destinations->begin(); itr != destinations->end(); itr++) {
  8733. destination = *itr;
  8734. 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)))
  8735. transport_list.push_back(destination);
  8736. }
  8737. if (transport_list.size() == 0 && destination) {
  8738. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  8739. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  8740. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  8741. else
  8742. {
  8743. EQ2Packet* app = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  8744. if (app)
  8745. QueuePacket(app);
  8746. }
  8747. }
  8748. else {
  8749. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  8750. // determine if this is an instanced zone that already exists
  8751. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(destination->destination_zone_id);
  8752. if (instance_zone || new_zone) {
  8753. GetPlayer()->SetX(destination->destination_x);
  8754. GetPlayer()->SetY(destination->destination_y);
  8755. GetPlayer()->SetZ(destination->destination_z);
  8756. GetPlayer()->SetHeading(destination->destination_heading);
  8757. if (instance_zone)
  8758. Zone(instance_zone->GetInstanceID(), false, true, is_spell);
  8759. else
  8760. Zone(new_zone, false, is_spell);
  8761. }
  8762. }
  8763. if (destination->message.length() > 0)
  8764. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  8765. }
  8766. else if (transport_list.size() > 0) {
  8767. if (!spawn->IsSoundsDisabled())
  8768. PlaySound("mariner_bell");
  8769. PacketStruct* packet = configReader.getStruct("WS_TeleportList", GetVersion());
  8770. if (packet) {
  8771. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  8772. // Put all the destinations the player can go in a new vector
  8773. vector<TransportDestination*> destinations;
  8774. for (int32 i = 0; i < transport_list.size(); i++) {
  8775. destination = transport_list.at(i);
  8776. // Check min level
  8777. if (destination->min_level > 0 && GetPlayer()->GetLevel() < destination->min_level)
  8778. continue;
  8779. // Check max level
  8780. if (destination->max_level > 0 && GetPlayer()->GetLevel() > destination->max_level)
  8781. continue;
  8782. // Check quest complete
  8783. if (destination->req_quest_complete > 0 && GetPlayer()->HasQuestBeenCompleted(destination->req_quest_complete) == 0)
  8784. continue;
  8785. // Check req quest and step
  8786. if (destination->req_quest > 0 && destination->req_quest_step > 0 && GetPlayer()->GetQuestStep(destination->req_quest) != destination->req_quest_step)
  8787. continue;
  8788. // 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
  8789. if (has_map && (destination->destination_zone_id == GetCurrentZone()->GetZoneID() && GetPlayer()->GetDistance(destination->destination_x, destination->destination_y, destination->destination_z) < 20)) {
  8790. packet->setDataByName("current_zone", destination->display_name.c_str());
  8791. packet->setDataByName("current_map_x", destination->map_x);
  8792. packet->setDataByName("current_map_y", destination->map_y);
  8793. }
  8794. else {
  8795. destinations.push_back(destination);
  8796. }
  8797. }
  8798. // Use the new vector to create the packet
  8799. destination = 0;
  8800. packet->setArrayLengthByName("num_destinations", destinations.size());
  8801. for (int32 i = 0; i < destinations.size(); i++) {
  8802. destination = destinations.at(i);
  8803. packet->setArrayDataByName("unique_id", destination->unique_id, i);
  8804. packet->setArrayDataByName("display_name", destination->display_name.c_str(), i);
  8805. packet->setArrayDataByName("zone_name", destination->display_name.c_str(), i);
  8806. packet->setArrayDataByName("zone_file_name", destination->display_name.c_str(), i);
  8807. packet->setArrayDataByName("cost", destination->cost, i);
  8808. if (has_map) {
  8809. packet->setArrayDataByName("map_x", destination->map_x, i);
  8810. packet->setArrayDataByName("map_y", destination->map_y, i);
  8811. }
  8812. }
  8813. if (has_map)
  8814. packet->setDataByName("map_name", GetCurrentZone()->GetTransportMap(transport_id).c_str());
  8815. EQ2Packet* app = packet->serialize();
  8816. //DumpPacket(app);
  8817. if (destinations.size() > 0)
  8818. QueuePacket(app);
  8819. safe_delete(packet);
  8820. }
  8821. }
  8822. }
  8823. void Client::ProcessTeleportLocation(EQApplicationPacket* app) {
  8824. PacketStruct* packet = configReader.getStruct("WS_TeleportDestination", GetVersion());
  8825. if (packet) {
  8826. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  8827. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(packet->getType_int32_ByName("spawn_id"));
  8828. int32 unique_id = packet->getType_int32_ByName("unique_id");
  8829. string zone_name = packet->getType_EQ2_16BitString_ByName("zone_name").data;
  8830. int32 cost = packet->getType_int32_ByName("cost");
  8831. vector<TransportDestination*> destinations;
  8832. TransportDestination* destination = 0;
  8833. if (this->GetTemporaryTransportID() || (spawn && spawn == transport_spawn && spawn->GetTransporterID()))
  8834. GetCurrentZone()->GetTransporters(&destinations, this, this->GetTemporaryTransportID() ? this->GetTemporaryTransportID() : spawn->GetTransporterID());
  8835. vector<TransportDestination*>::iterator itr;
  8836. for (itr = destinations.begin(); itr != destinations.end(); itr++) {
  8837. if ((*itr)->unique_id == unique_id && (*itr)->display_name == zone_name && (*itr)->cost == cost) {
  8838. destination = *itr;
  8839. break;
  8840. }
  8841. }
  8842. SetTemporaryTransportID(0);
  8843. if (!destination)
  8844. SimpleMessage(CHANNEL_COLOR_RED, "Error processing transport.");
  8845. else {
  8846. if (cost == 0 || player->RemoveCoins(cost)) {
  8847. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  8848. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  8849. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  8850. else
  8851. {
  8852. EQ2Packet* outapp = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  8853. if (outapp)
  8854. QueuePacket(outapp);
  8855. }
  8856. }
  8857. else {
  8858. GetPlayer()->SetX(destination->destination_x);
  8859. GetPlayer()->SetY(destination->destination_y);
  8860. GetPlayer()->SetZ(destination->destination_z);
  8861. GetPlayer()->SetHeading(destination->destination_heading);
  8862. // Test if where we're going is an Instanced zone
  8863. if (!TryZoneInstance(destination->destination_zone_id, false)) {
  8864. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Attempting to zone normally");
  8865. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  8866. Zone(new_zone, false);
  8867. }
  8868. }
  8869. if (destination->message.length() > 0)
  8870. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  8871. }
  8872. else
  8873. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough money to use this transport.");
  8874. }
  8875. }
  8876. safe_delete(packet);
  8877. }
  8878. }
  8879. void Client::SendNewSpells(int8 class_id) {
  8880. if (class_id > 0) {
  8881. vector<Spell*>* spells = master_spell_list.GetSpellListByAdventureClass(class_id, player->GetLevel(), 1);
  8882. AddSendNewSpells(spells);
  8883. safe_delete(spells);
  8884. }
  8885. }
  8886. void Client::SendNewTSSpells(int8 class_id) {
  8887. if (class_id > 0) {
  8888. vector<Spell*>* spells = master_spell_list.GetSpellListByTradeskillClass(class_id, player->GetLevel(), 1);
  8889. AddSendNewSpells(spells);
  8890. safe_delete(spells);
  8891. }
  8892. }
  8893. void Client::AddSendNewSpells(vector<Spell*>* spells) {
  8894. Spell* spell = 0;
  8895. bool send_updates = false;
  8896. vector<Spell*>::iterator itr;
  8897. for (itr = spells->begin(); itr != spells->end(); itr++) {
  8898. spell = *itr;
  8899. if (spell && !player->HasSpell(spell->GetSpellID(), spell->GetSpellTier(), true) && spell->GetSpellData()->lua_script.length() > 0) {
  8900. send_updates = true;
  8901. SendSpellUpdate(spell);
  8902. player->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), player->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  8903. player->UnlockSpell(spell);
  8904. }
  8905. }
  8906. if (send_updates) {
  8907. EQ2Packet* outapp = player->GetSpellBookUpdatePacket(GetVersion());
  8908. if (outapp)
  8909. QueuePacket(outapp);
  8910. }
  8911. }
  8912. void Client::SetItemSearch(vector<Item*>* items) {
  8913. if (items) {
  8914. safe_delete(search_items);
  8915. search_items = items;
  8916. }
  8917. }
  8918. vector<Item*>* Client::GetSearchItems() {
  8919. return search_items;
  8920. }
  8921. void Client::SearchStore(int32 page) {
  8922. if (search_items) {
  8923. PacketStruct* packet = configReader.getStruct("WS_BrokerItems", GetVersion());
  8924. if (packet) {
  8925. int32 x = page * 8;
  8926. if (search_items->size() > 8) {
  8927. if ((search_items->size() - x) > 8)
  8928. packet->setArrayLengthByName("num_items", 8);
  8929. else
  8930. packet->setArrayLengthByName("num_items", search_items->size() - x);
  8931. }
  8932. else
  8933. packet->setArrayLengthByName("num_items", search_items->size());
  8934. if (search_items->size() > 0) {
  8935. packet->setArrayLengthByName("num_sellers", 1);
  8936. packet->setArrayDataByName("seller_seller_id", 1);
  8937. packet->setDataByName("per_page", 8);
  8938. packet->setDataByName("num_pages", search_items->size() / 8 + 1);
  8939. packet->setDataByName("page", page);
  8940. Item* item = 0;
  8941. int32 limit = search_items->size() > 8 ? 8 : search_items->size();
  8942. for (int32 i = 0; i < limit; i++, x++) {
  8943. if (x >= search_items->size())
  8944. break;
  8945. item = search_items->at(x);
  8946. std::string teststr("test ");
  8947. teststr.append(std::to_string(i));
  8948. packet->setArrayDataByName("string_one", teststr.c_str(), i);
  8949. packet->setArrayDataByName("string_two", "testtwo", i);
  8950. packet->setArrayDataByName("seller_name", "EQ2EMuDev", i);
  8951. packet->setArrayDataByName("item_id", item->details.item_id, i);
  8952. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  8953. packet->setArrayDataByName("icon", item->details.icon, i);
  8954. //packet->setArrayDataByName("unknown2b", i, i);
  8955. packet->setArrayDataByName("item_seller_id", 1, i);
  8956. if (item->stack_count == 0)
  8957. packet->setArrayDataByName("quantity", 1, i);
  8958. else
  8959. packet->setArrayDataByName("quantity", item->stack_count, i);
  8960. packet->setArrayDataByName("stack_size", item->stack_count, i);
  8961. packet->setArrayDataByName("sell_price", item->sell_price, i);
  8962. std::string tmpStr("");
  8963. tmpStr.append(item->name.c_str());
  8964. tmpStr.append(" (");
  8965. tmpStr.append(std::to_string(item->details.item_id));
  8966. tmpStr.append(")");
  8967. packet->setArrayDataByName("item_name", tmpStr.c_str(), i);
  8968. packet->setArrayDataByName("req_level", item->generic_info.adventure_default_level, i);
  8969. //QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  8970. }
  8971. }
  8972. EQ2Packet* outapp = packet->serialize();
  8973. DumpPacket(outapp);
  8974. QueuePacket(outapp);
  8975. safe_delete(packet);
  8976. }
  8977. }
  8978. }
  8979. void Client::SetReadyForUpdates() {
  8980. if (!ready_for_updates) {
  8981. database.loadCharacterProperties(this);
  8982. SendDefaultGroupOptions();
  8983. }
  8984. ready_for_updates = true;
  8985. if(GetVersion() <= 561) {
  8986. SendRecipeList();
  8987. }
  8988. }
  8989. void Client::SetReadyForSpawns(bool val) {
  8990. ready_for_spawns = val;
  8991. if (GetPlayer()->GetActivityStatus() > 0) {
  8992. GetPlayer()->SetActivityStatus(0);
  8993. if (GetPlayer()->GetGroupMemberInfo()) {
  8994. world.GetGroupManager()->GroupMessage(GetPlayer()->GetGroupMemberInfo()->group_id, "%s has returned from Linkdead.", GetPlayer()->GetName());
  8995. }
  8996. }
  8997. GetPlayer()->SetActiveReward(false);
  8998. zone_list.CheckFriendZoned(this);
  8999. }
  9000. void Client::SendChatRelationship(int8 type, const char* name) {
  9001. if (!name) {
  9002. return;
  9003. }
  9004. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  9005. if (packet) {
  9006. packet->setDataByName("account_id", GetAccountID());
  9007. packet->setDataByName("type", type);
  9008. packet->setArrayLengthByName("num_names", 1);
  9009. packet->setArrayDataByName("name", name);
  9010. if (type == 0) {
  9011. Client* client = zone_list.GetClientByCharName(name);
  9012. if (client) {
  9013. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName());
  9014. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()));
  9015. }
  9016. }
  9017. QueuePacket(packet->serialize());
  9018. safe_delete(packet);
  9019. }
  9020. }
  9021. void Client::SendFriendList() {
  9022. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  9023. if (packet) {
  9024. packet->setDataByName("account_id", GetAccountID());
  9025. map<string, int8>::iterator itr;
  9026. map<string, int8>* friends = player->GetFriends();
  9027. if (friends && friends->size() > 0) {
  9028. Client* client = 0;
  9029. vector<string> names;
  9030. for (itr = friends->begin(); itr != friends->end(); itr++) {
  9031. if (itr->second == 2)
  9032. continue;
  9033. names.push_back(itr->first);
  9034. }
  9035. packet->setArrayLengthByName("num_names", names.size());
  9036. for (int32 i = 0; i < names.size(); i++) {
  9037. client = zone_list.GetClientByCharName(names[i]);
  9038. packet->setArrayDataByName("name", names[i].c_str(), i);
  9039. if (client) {
  9040. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName(), i);
  9041. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()), i);
  9042. }
  9043. }
  9044. }
  9045. QueuePacket(packet->serialize());
  9046. safe_delete(packet);
  9047. }
  9048. }
  9049. void Client::SendIgnoreList() {
  9050. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  9051. if (packet) {
  9052. packet->setDataByName("account_id", GetAccountID());
  9053. packet->setDataByName("type", 2);
  9054. map<string, int8>::iterator itr;
  9055. map<string, int8>* ignored = player->GetIgnoredPlayers();
  9056. if (ignored && ignored->size() > 0) {
  9057. vector<string> names;
  9058. for (itr = ignored->begin(); itr != ignored->end(); itr++) {
  9059. if (itr->second == 2)
  9060. continue;
  9061. names.push_back(itr->first);
  9062. }
  9063. packet->setArrayLengthByName("num_names", names.size());
  9064. for (int32 i = 0; i < names.size(); i++)
  9065. packet->setArrayDataByName("name", names[i].c_str(), i);
  9066. }
  9067. QueuePacket(packet->serialize());
  9068. safe_delete(packet);
  9069. }
  9070. }
  9071. void Client::AddWaypoint(string name, int8 type) {
  9072. waypoint_id++;
  9073. WaypointInfo info;
  9074. info.id = waypoint_id;
  9075. info.type = type;
  9076. waypoints[name] = info;
  9077. }
  9078. void Client::SendWaypoints() {
  9079. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  9080. if (packet) {
  9081. packet->setArrayLengthByName("num_updates", waypoints.size());
  9082. map<string, WaypointInfo>::iterator itr;
  9083. int16 i = 0;
  9084. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  9085. packet->setArrayDataByName("waypoint_name", itr->first.c_str(), i);
  9086. packet->setArrayDataByName("waypoint_category", itr->second.type, i);
  9087. packet->setArrayDataByName("spawn_id", itr->second.id, i);
  9088. i++;
  9089. }
  9090. packet->setDataByName("unknown", 0xFFFFFFFF);
  9091. QueuePacket(packet->serialize());
  9092. safe_delete(packet);
  9093. }
  9094. }
  9095. void Client::SelectWaypoint(int32 id) {
  9096. string found_name = "";
  9097. map<string, WaypointInfo>::iterator itr;
  9098. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  9099. if (itr->second.id == id) {
  9100. found_name = itr->first;
  9101. break;
  9102. }
  9103. }
  9104. if (found_name.length() > 0) {
  9105. Spawn* spawn = current_zone->FindSpawn(player, found_name.c_str());
  9106. ShowPathToTarget(spawn);
  9107. }
  9108. }
  9109. void Client::AddWaypoint(const char* waypoint_name, int8 waypoint_category, int32 spawn_id) {
  9110. if (waypoint_name) {
  9111. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  9112. if (packet) {
  9113. packet->setArrayLengthByName("num_updates", 1);
  9114. packet->setArrayDataByName("waypoint_name", waypoint_name, 0);
  9115. packet->setArrayDataByName("waypoint_category", waypoint_category, 0);
  9116. packet->setArrayDataByName("spawn_id", spawn_id, 0);
  9117. packet->setArrayDataByName("waypoint_category2", waypoint_category, 0);
  9118. packet->setArrayDataByName("spawn_id2", spawn_id, 0);
  9119. packet->setDataByName("unknown", 0xFFFFFFFF);
  9120. QueuePacket(packet->serialize());
  9121. safe_delete(packet);
  9122. }
  9123. }
  9124. }
  9125. void Client::ClearWaypoint() {
  9126. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  9127. if (packet) {
  9128. QueuePacket(packet->serialize());
  9129. safe_delete(packet);
  9130. }
  9131. }
  9132. bool Client::ShowPathToTarget(float x, float y, float z, float y_offset) {
  9133. if (current_zone->pathing) {
  9134. if (GetPlayer()->GetMap()) {
  9135. if (x < GetPlayer()->GetMap()->GetMinX() || x > GetPlayer()->GetMap()->GetMaxX())
  9136. return false;
  9137. if (z < GetPlayer()->GetMap()->GetMinZ() || z > GetPlayer()->GetMap()->GetMaxZ())
  9138. return false;
  9139. auto loc = glm::vec3(x, z, y);
  9140. float new_z = GetPlayer()->FindBestZ(loc, nullptr);
  9141. if (new_z != BEST_Z_INVALID) //this is actually y
  9142. y = new_z;
  9143. }
  9144. bool partial = false;
  9145. bool stuck = false;
  9146. PathfinderOptions opts;
  9147. opts.smooth_path = true;
  9148. opts.step_size = 100.0f;//RuleR(Pathing, NavmeshStepSize);
  9149. opts.offset = y_offset + 1.0f;
  9150. opts.flags = PathingNotDisabled ^ PathingZoneLine;
  9151. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  9152. if (packet) {
  9153. auto path = current_zone->pathing->FindPath(glm::vec3(player->GetX(), player->GetZ(), player->GetY()), glm::vec3(x, z, y), partial, stuck, opts);
  9154. packet->setArrayLengthByName("num_points", path.size());
  9155. int i = 0;
  9156. for (auto& node : path)
  9157. {
  9158. packet->setArrayDataByName("x", node.pos.x, i);
  9159. packet->setArrayDataByName("y", node.pos.z, i);
  9160. packet->setArrayDataByName("z", node.pos.y, i);
  9161. packet->setDataByName("waypoint_x", x);
  9162. packet->setDataByName("waypoint_y", y);
  9163. packet->setDataByName("waypoint_z", z);
  9164. i++;
  9165. }
  9166. if (i > 0)
  9167. QueuePacket(packet->serialize());
  9168. safe_delete(packet);
  9169. return (i > 0);
  9170. }
  9171. }
  9172. return false;
  9173. }
  9174. bool Client::ShowPathToTarget(Spawn* spawn) {
  9175. if (spawn) {
  9176. return ShowPathToTarget(spawn->GetX(), spawn->GetY(), spawn->GetZ(), spawn->GetYOffset());
  9177. }
  9178. return false;
  9179. }
  9180. void Client::BeginWaypoint(const char* waypoint_name, float x, float y, float z) {
  9181. if (waypoint_name) {
  9182. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  9183. if (packet) {
  9184. packet->setArrayLengthByName("num_points", 1);
  9185. packet->setArrayDataByName("x", x, 0);
  9186. packet->setArrayDataByName("y", y, 0);
  9187. packet->setArrayDataByName("z", z, 0);
  9188. packet->setDataByName("waypoint_x", x);
  9189. packet->setDataByName("waypoint_y", y);
  9190. packet->setDataByName("waypoint_z", z);
  9191. packet->setDataByName("waypoint_name", waypoint_name);
  9192. packet->setDataByName("unknown", 0);
  9193. QueuePacket(packet->serialize());
  9194. safe_delete(packet);
  9195. }
  9196. }
  9197. }
  9198. void Client::InspectPlayer(Player* player_to_inspect) {
  9199. int source_pvp_alignment = GetPlayer()->GetPVPAlignment();
  9200. int target_pvp_alignment = player_to_inspect->GetPVPAlignment();
  9201. bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
  9202. if(pvp_allowed == true){
  9203. if(source_pvp_alignment != target_pvp_alignment){
  9204. Message(CHANNEL_COLOR_RED, "You can not inspect players of different alignments.");
  9205. return;
  9206. }
  9207. }
  9208. if (player_to_inspect && player_to_inspect->GetClient()) {
  9209. PacketStruct* packet = configReader.getStruct("WS_InspectPlayer", GetVersion());
  9210. if (packet) {
  9211. packet->setDataByName("unknown", 0);
  9212. packet->setSmallStringByName("name", player_to_inspect->GetName());
  9213. packet->setDataByName("race", player_to_inspect->GetRace());
  9214. packet->setDataByName("gender", player_to_inspect->GetGender());
  9215. packet->setDataByName("adventure_level", player_to_inspect->GetLevel());
  9216. int16 effective_level = player_to_inspect->GetInfoStruct()->get_effective_level() != 0 ? player_to_inspect->GetInfoStruct()->get_effective_level() : player_to_inspect->GetLevel();
  9217. packet->setDataByName("adventure_level_effective", effective_level);
  9218. packet->setDataByName("adventure_class", player_to_inspect->GetAdventureClass());
  9219. packet->setDataByName("tradeskill_level", player_to_inspect->GetTSLevel());
  9220. packet->setDataByName("tradeskill_class", player_to_inspect->GetTradeskillClass());
  9221. packet->setDataByName("health", player_to_inspect->GetHP());
  9222. packet->setDataByName("health_max", player_to_inspect->GetTotalHP());
  9223. packet->setDataByName("health_base", player_to_inspect->GetTotalHPBase());
  9224. packet->setDataByName("power", player_to_inspect->GetPower());
  9225. packet->setDataByName("power_max", player_to_inspect->GetTotalPower());
  9226. packet->setDataByName("power_base", player_to_inspect->GetTotalPowerBase());
  9227. packet->setDataByName("mitigation", player_to_inspect->GetInfoStruct()->get_cur_mitigation());
  9228. packet->setDataByName("unknown1", 0);
  9229. packet->setDataByName("avoidance", player_to_inspect->GetInfoStruct()->get_avoidance_display()*10.0f);
  9230. packet->setDataByName("unknown2", 0);
  9231. packet->setDataByName("mitigation_percentage", 0);
  9232. packet->setDataByName("strength", player_to_inspect->GetStr());
  9233. packet->setDataByName("strength_base", player_to_inspect->GetStrBase());
  9234. packet->setDataByName("stamina", player_to_inspect->GetSta());
  9235. packet->setDataByName("stamina_base", player_to_inspect->GetStaBase());
  9236. packet->setDataByName("agility", player_to_inspect->GetAgi());
  9237. packet->setDataByName("agility_base", player_to_inspect->GetAgiBase());
  9238. packet->setDataByName("wisdom", player_to_inspect->GetWis());
  9239. packet->setDataByName("wisdom_base", player_to_inspect->GetWisBase());
  9240. packet->setDataByName("intelligence", player_to_inspect->GetInt());
  9241. packet->setDataByName("intelligence_base", player_to_inspect->GetIntBase());
  9242. packet->setDataByName("unknown4", 0);
  9243. packet->setDataByName("unknown5", 0);
  9244. packet->setDataByName("unknown6", 0);
  9245. packet->setDataByName("unknown7", 0);
  9246. packet->setDataByName("unknown8", 0);
  9247. packet->setDataByName("unknown9", 0);
  9248. packet->setDataByName("unknown10", 0);
  9249. packet->setDataByName("unknown11", 0);
  9250. packet->setDataByName("unknown12", 0);
  9251. packet->setDataByName("heat_resist", player_to_inspect->GetHeatResistance());
  9252. packet->setDataByName("heat_resist_base", player_to_inspect->GetHeatResistanceBase());
  9253. packet->setDataByName("heat_resist_percentage", 0);
  9254. packet->setDataByName("cold_resist", player_to_inspect->GetColdResistance());
  9255. packet->setDataByName("cold_resist_base", player_to_inspect->GetColdResistanceBase());
  9256. packet->setDataByName("cold_resist_percentage", 0);
  9257. packet->setDataByName("magic_resist", player_to_inspect->GetMagicResistance());
  9258. packet->setDataByName("magic_resist_base", player_to_inspect->GetMagicResistanceBase());
  9259. packet->setDataByName("magic_resist_percentage", 0);
  9260. packet->setDataByName("mental_resist", player_to_inspect->GetMentalResistance());
  9261. packet->setDataByName("mental_resist_base", player_to_inspect->GetMentalResistanceBase());
  9262. packet->setDataByName("mental_resist_percentage", 0);
  9263. packet->setDataByName("divine_resist", player_to_inspect->GetDivineResistance());
  9264. packet->setDataByName("divine_resist_base", player_to_inspect->GetDivineResistanceBase());
  9265. packet->setDataByName("divine_resist_percentage", 0);
  9266. packet->setDataByName("disease_resist", player_to_inspect->GetDiseaseResistance());
  9267. packet->setDataByName("disease_resist_base", player_to_inspect->GetDiseaseResistanceBase());
  9268. packet->setDataByName("disease_resist_percentage", 0);
  9269. packet->setDataByName("poison_resist", player_to_inspect->GetPoisonResistance());
  9270. packet->setDataByName("poison_resist_base", player_to_inspect->GetPoisonResistanceBase());
  9271. packet->setDataByName("poison_resist_percentage", 0);
  9272. packet->setArrayLengthByName("num_chars", 0x01FF);
  9273. string biography = player_to_inspect->GetBiography();
  9274. for (size_t i = 0; i < biography.length(); i++)
  9275. packet->setArrayDataByName("biography_char", biography[i], i);
  9276. if(GetVersion() <= 373) {
  9277. for(int32 s=0;s<20;s++) {
  9278. int32 slot = s;
  9279. char item_slot_name[64], item_slot_name_appearance[64];
  9280. _snprintf(item_slot_name,64,"slot_%u",slot);
  9281. Item* pw = player_to_inspect->GetEquipmentList()->GetItem(GetPlayer()->ConvertSlotFromClient(s, GetVersion()));
  9282. packet->setItemByName(item_slot_name, pw, this->GetPlayer(), 0, 7, true, true, true);
  9283. }
  9284. }
  9285. else if(GetVersion() <= 561) {
  9286. for(int32 s=0;s<22;s++) {
  9287. int32 slot = s;
  9288. char item_slot_name[64], item_slot_name_appearance[64];
  9289. _snprintf(item_slot_name,64,"slot_%u",slot);
  9290. Item* pw = player_to_inspect->GetEquipmentList()->GetItem(GetPlayer()->ConvertSlotFromClient(s, GetVersion()));
  9291. packet->setItemByName(item_slot_name, pw, this->GetPlayer(), 0, 5, true, true);
  9292. }
  9293. }
  9294. else {
  9295. for(int32 s=0;s<NUM_SLOTS;s++) {
  9296. int32 slot = s*2;
  9297. char item_slot_name[64], item_slot_name_appearance[64];
  9298. _snprintf(item_slot_name,64,"slot_%u",slot);
  9299. int32 slot_appearance = (s*2)+1;
  9300. _snprintf(item_slot_name_appearance,64,"slot_%u",slot_appearance);
  9301. Item* pw = player_to_inspect->GetEquipmentList()->GetItem(GetPlayer()->ConvertSlotFromClient(s, player_to_inspect->GetClient()->GetVersion()));
  9302. packet->setItemByName(item_slot_name, pw, this->GetPlayer(), 0, 13, false, true);
  9303. if(s <= EQ2_FEET_SLOT || s == EQ2_RANGE_SLOT || s == EQ2_CLOAK_SLOT) {
  9304. pw = player_to_inspect->GetAppearanceEquipmentList()->GetItem(s);
  9305. packet->setItemByName(item_slot_name_appearance, pw, this->GetPlayer(), 0, 13, false, true);
  9306. }
  9307. else {
  9308. packet->setItemByName(item_slot_name_appearance, nullptr, this->GetPlayer(), 0, 13, false, true);
  9309. }
  9310. }
  9311. }
  9312. QueuePacket(packet->serialize());
  9313. safe_delete(packet);
  9314. }
  9315. }
  9316. }
  9317. void Client::SetPendingGuildInvite(Guild* guild, Player* invited_by) {
  9318. pending_guild_invite.guild = guild;
  9319. pending_guild_invite.invited_by = invited_by;
  9320. }
  9321. void Client::ShowClaimWindow() {
  9322. PacketStruct* packet = configReader.getStruct("WS_PromoFlagsDetails", GetVersion());
  9323. if (packet) {
  9324. int16 loaded = database.CountCharClaimItems(GetCharacterID());
  9325. vector<ClaimItems> claim = database.LoadCharacterClaimItems(GetCharacterID());
  9326. int32 account_age = database.GetAccountAge(GetAccountID());
  9327. //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.
  9328. if (loaded == 0 || claim.empty()) {
  9329. Message(CHANNEL_COLOR_RED, "You have nothing to claim.");
  9330. return;
  9331. }
  9332. packet->setArrayLengthByName("num_claim_items", loaded);
  9333. int j = 0; //use this to track skipped vet items.
  9334. for (int i = 0; i < claim.size(); i++)
  9335. {
  9336. if (j == claim.size()) {
  9337. Message(CHANNEL_COLOR_RED, "You have nothing to claim.");
  9338. return;
  9339. }
  9340. Item* item = master_item_list.GetItem(claim[i].item_id);
  9341. int16 claimed = 0;
  9342. if (claim[i].curr_claim < claim[i].max_claim) {
  9343. claimed = claim[i].max_claim - claim[i].curr_claim;
  9344. }
  9345. else {
  9346. claimed = 0;
  9347. }
  9348. //dont display vet rewards until they reach the age required
  9349. if (account_age < claim[i].vet_reward_time) {
  9350. j++;
  9351. continue;
  9352. }
  9353. packet->setArrayDataByName("id", i, i);
  9354. packet->setArrayDataByName("not_yet_claimed", 1, i);
  9355. packet->setArrayDataByName("num_remaining", claim[i].curr_claim, i);
  9356. packet->setArrayDataByName("one_per_character", claim[i].one_per_char, i);
  9357. packet->setArrayDataByName("claimed_on_this_char", 0, i);
  9358. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  9359. packet->setArrayDataByName("text", "If you ever see this text, let a developer know!", i); //I've not seen this!
  9360. //packet->setArrayDataByName("category", "Scott's Shit", i); //devn00b: not using so commenting out, leaving in case we ever do implement categories.
  9361. packet->setArrayDataByName("icon", item->details.icon, i);
  9362. packet->setArrayDataByName("item_id", item->details.item_id, i);
  9363. j++;
  9364. }
  9365. }
  9366. packet->setDataByName("unknown3", 1);
  9367. QueuePacket(packet->serialize());
  9368. safe_delete(packet);
  9369. }
  9370. void Client::ShowGuildSearchWindow() {
  9371. PacketStruct* packet = configReader.getStruct("WS_GuildRecruiting", GetVersion());
  9372. if (packet) {
  9373. MutexMap<int32, Guild*>* guilds = guild_list.GetGuilds();
  9374. MutexMap<int32, Guild*>::iterator itr = guilds->begin();
  9375. packet->setArrayLengthByName("num_guilds", guilds->size());
  9376. int32 i = 0;
  9377. while (itr.Next()) {
  9378. Guild* guild = itr.second;
  9379. packet->setArrayDataByName("guild_id", guild->GetID(), i);
  9380. packet->setArrayDataByName("guild_name", guild->GetName(), i);
  9381. packet->setArrayDataByName("recruiting_short_description", guild->GetRecruitingShortDesc().c_str(), i);
  9382. packet->setArrayDataByName("descriptive_tag1", guild->GetRecruitingDescTag(0), i);
  9383. packet->setArrayDataByName("descriptive_tag2", guild->GetRecruitingDescTag(1), i);
  9384. packet->setArrayDataByName("descriptive_tag3", guild->GetRecruitingDescTag(2), i);
  9385. packet->setArrayDataByName("descriptive_tag4", guild->GetRecruitingDescTag(3), i);
  9386. packet->setArrayDataByName("playstyle", guild->GetRecruitingPlayStyle(), i);
  9387. packet->setArrayDataByName("looking_for", guild->GetRecruitingLookingForPacketValue(), i); //tradeskillers, fighters, new
  9388. packet->setArrayDataByName("unknown7", 0x02, i);
  9389. packet->setArrayDataByName("min_level", guild->GetRecruitingMinLevel(), i);
  9390. i++;
  9391. }
  9392. QueuePacket(packet->serialize());
  9393. safe_delete(packet);
  9394. }
  9395. }
  9396. void Client::ShowDressingRoom(Item* item, sint32 crc) {
  9397. PacketStruct* packet;
  9398. vector<int8>* slot_data;
  9399. vector<int8>::iterator itr;
  9400. int32 slots = 0;
  9401. assert(item);
  9402. if (!(packet = configReader.getStruct("WS_DressingRoom", GetVersion()))) {
  9403. return;
  9404. }
  9405. slot_data = &item->slot_data;
  9406. for (itr = slot_data->begin(); itr != slot_data->end(); itr++) {
  9407. if (version >= 1188)
  9408. slots = *itr;
  9409. else
  9410. slots += (int8)pow(2.0, *itr);
  9411. }
  9412. packet->setDataByName("slot", slots);
  9413. packet->setDataByName("appearance_id", item->generic_info.appearance_id);
  9414. if (slots == 2) {
  9415. packet->setDataByName("rgb", item->generic_info.appearance_red, 2);
  9416. packet->setDataByName("rgb", item->generic_info.appearance_blue, 0);
  9417. }
  9418. else {
  9419. packet->setDataByName("rgb", item->generic_info.appearance_red, 0);
  9420. packet->setDataByName("rgb", item->generic_info.appearance_blue, 2);
  9421. }
  9422. packet->setDataByName("rgb", item->generic_info.appearance_green, 1);
  9423. if (slots == 4) {
  9424. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 2);
  9425. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  9426. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 0);
  9427. }
  9428. else if (slots == 7) {
  9429. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 1);
  9430. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 0);
  9431. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  9432. }
  9433. else {
  9434. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 0);
  9435. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  9436. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  9437. }
  9438. packet->setDataByName("icon", item->details.icon);
  9439. packet->setDataByName("item_id", item->details.item_id);
  9440. packet->setDataByName("item_crc", crc);
  9441. packet->setDataByName("unknown2", 0xFFFFFFFF);
  9442. packet->setDataByName("unknown4", 0xFFFFFFFF);
  9443. packet->setDataByName("unknown5", 0xFF, 9);
  9444. packet->setDataByName("unknown5", 0xFF, 10);
  9445. QueuePacket(packet->serialize());
  9446. safe_delete(packet);
  9447. }
  9448. void Client::SendCollectionList() {
  9449. map<int32, Collection*>* collections = player->GetCollectionList()->GetCollections();
  9450. map<int32, Collection*>::iterator itr;
  9451. vector<struct CollectionItem*>* collection_items;
  9452. Collection* collection;
  9453. struct CollectionItem* collection_item;
  9454. PacketStruct* packet = 0;
  9455. int16 i = 0, j;
  9456. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version)))
  9457. return;
  9458. packet->setArrayLengthByName("num_collections", collections->size());
  9459. for (itr = collections->begin(); itr != collections->end(); itr++) {
  9460. collection = itr->second;
  9461. collection_items = collection->GetCollectionItems();
  9462. packet->setArrayDataByName("unknown", 1, i);
  9463. packet->setArrayDataByName("collection_name", collection->GetName(), i);
  9464. packet->setArrayDataByName("collection_category", collection->GetCategory(), i);
  9465. packet->setArrayDataByName("completed", collection->GetCompleted(), i);
  9466. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  9467. packet->setArrayDataByName("level", collection->GetLevel(), i);
  9468. packet->setArrayDataByName("ready_to_turn_in", collection->GetIsReadyToTurnIn(), i);
  9469. packet->setSubArrayLengthByName("num_items", collection_items->size(), i);
  9470. for (j = 0; j < collection_items->size(); j++) {
  9471. collection_item = collection_items->at(j);
  9472. Item* item = master_item_list.GetItem(collection_item->item);
  9473. if (item) {
  9474. packet->setSubArrayDataByName("item_icon", item->details.icon, i, j);
  9475. if (version < 955)
  9476. packet->setSubArrayDataByName("item_name", item->name.c_str(), i, j);
  9477. else
  9478. packet->setSubArrayDataByName("item_id", item->details.item_id, i, j);
  9479. }
  9480. packet->setSubArrayDataByName("item_flag", collection_item->found, i, j);
  9481. }
  9482. i++;
  9483. }
  9484. packet->setDataByName("new_collection_flag", 1);
  9485. QueuePacket(packet->serialize());
  9486. safe_delete(packet);
  9487. }
  9488. bool Client::SendCollectionsForItem(Item* item) {
  9489. map<int32, Collection*> collections_to_send;
  9490. map<int32, Collection*>* collections;
  9491. map<int32, Collection*>::iterator itr;
  9492. vector<struct CollectionItem*>* collection_items;
  9493. Collection* collection;
  9494. struct CollectionItem* collection_item;
  9495. PacketStruct* packet;
  9496. int16 i;
  9497. assert(item);
  9498. /* get any collections required by this item that the player already has */
  9499. collections = player->GetCollectionList()->GetCollections();
  9500. for (itr = collections->begin(); itr != collections->end(); itr++) {
  9501. collection = itr->second;
  9502. if (!collection->GetCompleted() && !collection->GetIsReadyToTurnIn() && collection->NeedsItem(item)) {
  9503. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from player list %u\n", collection->GetID());
  9504. collections_to_send[collection->GetID()] = collection;
  9505. }
  9506. }
  9507. /* get any collections required by this item that the player does not have and send it to the client */
  9508. collections = master_collection_list.GetCollections();
  9509. for (itr = collections->begin(); itr != collections->end(); itr++) {
  9510. collection = itr->second;
  9511. if (collection->NeedsItem(item) && !player->GetCollectionList()->GetCollection(collection->GetID())) {
  9512. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version))) {
  9513. return false;
  9514. }
  9515. packet->setArrayLengthByName("num_collections", 1);
  9516. packet->setArrayDataByName("unknown", 1, 0);
  9517. packet->setArrayDataByName("collection_name", collection->GetName(), 0);
  9518. packet->setArrayDataByName("collection_category", collection->GetCategory(), 0);
  9519. packet->setArrayDataByName("completed", 0, 0);
  9520. packet->setArrayDataByName("collection_id", collection->GetID(), 0);
  9521. packet->setArrayDataByName("level", collection->GetLevel(), 0);
  9522. packet->setArrayDataByName("ready_to_turn_in", 0, 0);
  9523. packet->setArrayDataByName("unknown3", 0x28, 0);
  9524. collection_items = collection->GetCollectionItems();
  9525. packet->setSubArrayLengthByName("num_items", collection_items->size(), 0);
  9526. for (i = 0; i < collection_items->size(); i++) {
  9527. collection_item = collection_items->at(i);
  9528. Item* item2 = master_item_list.GetItem(collection_item->item);
  9529. if (item2) {
  9530. packet->setSubArrayDataByName("item_icon", item2->details.icon, 0, i);
  9531. if (version < 955)
  9532. packet->setSubArrayDataByName("item_name", item2->name.c_str(), 0, i);
  9533. else
  9534. packet->setSubArrayDataByName("item_id", item2->details.item_id, 0, i);
  9535. packet->setSubArrayDataByName("item_flag", collection_item->found, 0, i);
  9536. }
  9537. }
  9538. packet->setDataByName("new_collection_flag", 0);
  9539. QueuePacket(packet->serialize());
  9540. safe_delete(packet);
  9541. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from master list %u\n", collection->GetID());
  9542. collections_to_send[collection->GetID()] = collection;
  9543. }
  9544. }
  9545. /* send the client a list of collections that should be filtered for this item */
  9546. if (collections_to_send.size() > 0) {
  9547. if (!(packet = configReader.getStruct("WS_CollectionFilter", version))) {
  9548. return false;
  9549. }
  9550. i = 0;
  9551. packet->setArrayLengthByName("num_filters", collections_to_send.size());
  9552. for (itr = collections_to_send.begin(); itr != collections_to_send.end(); itr++) {
  9553. collection = itr->second;
  9554. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  9555. packet->setArrayDataByName("collection_item_num", collection->GetCollectionItemByItemID(item->details.item_id)->index, i);
  9556. i++;
  9557. }
  9558. packet->setDataByName("item_icon", item->details.icon);
  9559. packet->setDataByName("item_name", item->name.c_str());
  9560. packet->setDataByName("item_id", item->details.item_id);
  9561. packet->setDataByName("unknown3", player->GetCollectionList()->Size());
  9562. QueuePacket(packet->serialize());
  9563. safe_delete(packet);
  9564. }
  9565. return collections_to_send.size() > 0;
  9566. }
  9567. void Client::HandleCollectionAddItem(int32 collection_id, Item* item) {
  9568. Collection* collection;
  9569. struct CollectionItem* collection_item;
  9570. PacketStruct* packet;
  9571. char tmp[200] = { 0 };
  9572. assert(item);
  9573. /* first try to get the collection from the player's collection list. if it's not found, get it from the master list */
  9574. if ((collection = player->GetCollectionList()->GetCollection(collection_id))) {
  9575. /* get the item struct that represents the item for this collection */
  9576. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  9577. SendCollectionList();
  9578. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  9579. return;
  9580. }
  9581. /* sanity check */
  9582. if (collection_item->found) {
  9583. SendCollectionList();
  9584. 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());
  9585. return;
  9586. }
  9587. }
  9588. else if ((collection = master_collection_list.GetCollection(collection_id))) {
  9589. collection = new Collection(collection);
  9590. /* get the item struct that represents the item for this collection */
  9591. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  9592. SendCollectionList();
  9593. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  9594. safe_delete(collection);
  9595. return;
  9596. }
  9597. /* add the new collection to the player's collection list */
  9598. if (!player->GetCollectionList()->AddCollection(collection)) {
  9599. SendCollectionList();
  9600. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Player '%s' already has collection '%s'", player->GetName(), collection->GetName());
  9601. safe_delete(collection);
  9602. return;
  9603. }
  9604. }
  9605. else {
  9606. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find collection with id %u", collection_id);
  9607. return;
  9608. }
  9609. collection_item->found = 1;
  9610. collection->SetSaveNeeded(true);
  9611. if (!(packet = configReader.getStruct("WS_CollectionItem", version))) {
  9612. SendCollectionList();
  9613. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find struct 'WS_CollectionItem'");
  9614. return;
  9615. }
  9616. packet->setDataByName("collection_id", collection_id);
  9617. packet->setDataByName("collection_item_num", collection_item->index);
  9618. packet->setDataByName("add", 1);
  9619. QueuePacket(packet->serialize());
  9620. Item* item2 = master_item_list.GetItem(collection_item->item);
  9621. if (item2) {
  9622. Message(CHANNEL_COLOR_YELLOW, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  9623. sprintf(tmp, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  9624. SendPopupMessage(5, tmp, "quest_item", 3.5, 0x64, 0xFF, 0xFF);
  9625. }
  9626. safe_delete(packet);
  9627. RemoveItem(item, 1);
  9628. SendCollectionList();
  9629. }
  9630. void Client::DisplayCollectionComplete(Collection* collection) {
  9631. vector<struct CollectionRewardItem*>* reward_items;
  9632. vector<struct CollectionRewardItem*>* selectable_reward_items;
  9633. struct CollectionRewardItem* reward_item;
  9634. PacketStruct* packet;
  9635. int32 i;
  9636. assert(collection);
  9637. reward_items = collection->GetRewardItems();
  9638. selectable_reward_items = collection->GetSelectableRewardItems();
  9639. if (GetVersion() <= 561) {
  9640. int32 source_id = collection->GetID();
  9641. PacketStruct* packet2 = configReader.getStruct("WS_QuestRewardPackMsg", GetVersion());
  9642. if (packet2) {
  9643. packet2->setSubstructDataByName("reward_data", "unknown1", 255);
  9644. packet2->setSubstructDataByName("reward_data", "reward", "Quest Reward!");
  9645. packet2->setSubstructDataByName("reward_data", "max_coin", collection->GetRewardCoin());
  9646. packet2->setSubstructDataByName("reward_data", "exp_bonus", collection->GetRewardXP());
  9647. if(reward_items){
  9648. int32 item_count = reward_items->size();
  9649. packet2->setSubstructArrayLengthByName("reward_data", "num_rewards", item_count);
  9650. i = 0;
  9651. if(reward_items) {
  9652. for (i = 0; i < reward_items->size(); i++) {
  9653. Item* item = reward_items->at(i)->item;
  9654. if (item) {
  9655. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  9656. packet2->setItemArrayDataByName("item", item, player, i, 0, GetClientItemPacketOffset());
  9657. }
  9658. }
  9659. }
  9660. }
  9661. if (selectable_reward_items) {
  9662. packet2->setSubstructArrayLengthByName("reward_data", "num_select_rewards", selectable_reward_items->size());
  9663. for (i = 0; i < selectable_reward_items->size(); i++) {
  9664. Item* item = selectable_reward_items->at(i)->item;
  9665. if (item) {
  9666. packet2->setArrayDataByName("select_reward_id", item->details.item_id, i);
  9667. packet2->setItemArrayDataByName("select_item", item, player, i, 0, GetClientItemPacketOffset());
  9668. }
  9669. }
  9670. }
  9671. }
  9672. EQ2Packet* app = packet2->serialize();
  9673. QueuePacket(app);
  9674. safe_delete(packet2);
  9675. return;
  9676. }
  9677. if (!(packet = configReader.getStruct("WS_QuestComplete", version))) {
  9678. return;
  9679. }
  9680. packet->setDataByName("title", "Quest Reward!");
  9681. packet->setDataByName("name", collection->GetName());
  9682. packet->setDataByName("description", collection->GetCategory());
  9683. packet->setDataByName("level", collection->GetLevel());
  9684. packet->setDataByName("max_coin", collection->GetRewardCoin());
  9685. packet->setDataByName("min_coin", collection->GetRewardCoin());
  9686. //packet->setDataByName("status_points", quest->GetStatusPoints());
  9687. packet->setArrayLengthByName("num_rewards", reward_items->size());
  9688. for (i = 0; i < reward_items->size(); i++) {
  9689. reward_item = reward_items->at(i);
  9690. if(!reward_item->item)
  9691. {
  9692. LogWrite(DATABASE__ERROR, 0, "Database", "DisplayCollectionComplete Collection %s (%u) num_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  9693. Message(CHANNEL_COLOR_RED, "DisplayCollectionComplete Collection %s (%u) num_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  9694. continue;
  9695. }
  9696. packet->setArrayDataByName("reward_id", reward_item->item->details.item_id, i);
  9697. if (version < 860)
  9698. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, GetClientItemPacketOffset());
  9699. else if (version < 1193)
  9700. packet->setItemArrayDataByName("item", reward_item->item, player, i);
  9701. else
  9702. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, 2);
  9703. }
  9704. packet->setArrayLengthByName("num_select_rewards", selectable_reward_items->size());
  9705. for (i = 0; i < selectable_reward_items->size(); i++) {
  9706. reward_item = selectable_reward_items->at(i);
  9707. if(!reward_item->item)
  9708. {
  9709. LogWrite(DATABASE__ERROR, 0, "Database", "DisplayCollectionComplete Collection %s (%u) num_select_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  9710. Message(CHANNEL_COLOR_RED, "DisplayCollectionComplete Collection %s (%u) num_select_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  9711. continue;
  9712. }
  9713. packet->setArrayDataByName("select_reward_id", reward_item->item->details.item_id, i);
  9714. if (version < 860)
  9715. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, GetClientItemPacketOffset());
  9716. else if (version < 1193)
  9717. packet->setItemArrayDataByName("select_item", reward_item->item, player, i);
  9718. else
  9719. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, 2);
  9720. }
  9721. QueuePacket(packet->serialize());
  9722. safe_delete(packet);
  9723. }
  9724. void Client::HandInCollections() {
  9725. map<int32, Collection*>* collections;
  9726. map<int32, Collection*>::iterator itr;
  9727. Collection* collection;
  9728. /* only show 1 collection reward dialog at a time */
  9729. if (player->GetPendingCollectionReward()) {
  9730. return;
  9731. }
  9732. collections = player->GetCollectionList()->GetCollections();
  9733. /* 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
  9734. for this collection, this function gets called again and the process repeats until there are no more collections to hand in */
  9735. for (itr = collections->begin(); itr != collections->end(); itr++) {
  9736. collection = itr->second;
  9737. if (collection->GetIsReadyToTurnIn()) {
  9738. player->SetPendingCollectionReward(collection);
  9739. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  9740. QuestRewardData* data = new QuestRewardData;
  9741. data->quest_id = 0;
  9742. data->is_temporary = false;
  9743. data->description = std::string("");
  9744. data->is_collection = true;
  9745. data->has_displayed = false;
  9746. data->tmp_coin = 0;
  9747. data->tmp_status = 0;
  9748. data->db_saved = false;
  9749. data->db_index = 0;
  9750. quest_pending_reward.push_back(data);
  9751. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  9752. quest_updates = true;
  9753. break;
  9754. }
  9755. }
  9756. if(quest_updates) {
  9757. SaveQuestRewardData(true);
  9758. }
  9759. }
  9760. void Client::AcceptCollectionRewards(Collection* collection, int32 selectable_item_id) {
  9761. vector<struct CollectionRewardItem*>* reward_items;
  9762. vector<struct CollectionRewardItem*>::iterator itr;
  9763. struct CollectionRewardItem* reward_item;
  9764. int16 num_slots_needed;
  9765. int16 num_slots;
  9766. assert(collection);
  9767. reward_items = collection->GetRewardItems();
  9768. num_slots_needed = (int16)reward_items->size();
  9769. if (selectable_item_id > 0)
  9770. num_slots_needed++;
  9771. num_slots = player->GetPlayerItemList()->GetNumberOfFreeSlots();
  9772. if (num_slots < num_slots_needed) {
  9773. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots. Free up some slots and try again");
  9774. DisplayCollectionComplete(collection);
  9775. return;
  9776. }
  9777. /* add manditory items */
  9778. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  9779. reward_item = *itr;
  9780. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  9781. }
  9782. /* find and add the selectable item if there's one */
  9783. if (selectable_item_id > 0) {
  9784. reward_items = collection->GetSelectableRewardItems();
  9785. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  9786. reward_item = *itr;
  9787. if (reward_item->item->details.item_id == selectable_item_id) {
  9788. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  9789. break;
  9790. }
  9791. }
  9792. }
  9793. if (collection->GetRewardXP() > 0) {
  9794. player->AddXP((int32)collection->GetRewardXP());
  9795. }
  9796. if (collection->GetRewardCoin() > 0) {
  9797. player->AddCoins(collection->GetRewardCoin());
  9798. Message(CHANNEL_COLOR_YELLOW, "You receive %s", GetCoinMessage(collection->GetRewardCoin()).c_str());
  9799. }
  9800. collection->SetCompleted(true);
  9801. //update achievements for completeing collection here
  9802. collection->SetSaveNeeded(true);
  9803. SendCollectionList();
  9804. /* reset the pending collection reward and check for my collections that the player needs to hand in */
  9805. player->SetPendingCollectionReward(0);
  9806. RemoveQueuedQuestReward();
  9807. GetPlayer()->SetActiveReward(false);
  9808. HandInCollections();
  9809. GetPlayer()->GetZone()->SendSubSpawnUpdates(SUBSPAWN_TYPES::COLLECTOR);
  9810. }
  9811. void Client::SendRecipeList() {
  9812. if(GetRecipeListSent()) {
  9813. return;
  9814. }
  9815. PacketStruct* packet = 0;
  9816. map<int32, Recipe*>* recipes = player->GetRecipeList()->GetRecipes();
  9817. map<int32, Recipe*>::iterator itr;
  9818. int16 i = 0;
  9819. Recipe* recipe;
  9820. if(version <= 561) {
  9821. PacketStruct* packet = 0;
  9822. if (!(packet = configReader.getStruct("WS_UpdateRecipeBook", GetVersion()))) {
  9823. return;
  9824. }
  9825. packet->setArrayLengthByName("recipe_count", recipes->size());
  9826. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  9827. recipe = itr->second;
  9828. int32 recipe_id = recipe->GetID();
  9829. packet->setArrayDataByName("recipe_id", recipe_id, i);
  9830. packet->setArrayDataByName("recipe_data_crc", GetRecipeCRC(recipe), i);
  9831. packet->setArrayDataByName("unknown", 0x7005BE3, i); //0x7005BE3
  9832. i++;
  9833. }
  9834. //packet->PrintPacket();
  9835. EQ2Packet* ret = packet->serializeCountPacket(GetVersion(), 0, nullptr, nullptr);
  9836. QueuePacket(ret);
  9837. safe_delete(packet);
  9838. SetRecipeListSent(true);
  9839. return;
  9840. }
  9841. else if (!(packet = configReader.getStruct("WS_RecipeList", version))) {
  9842. return;
  9843. }
  9844. int8 level = player->GetTSLevel();
  9845. int index = 0;
  9846. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  9847. recipe = itr->second;
  9848. auto res = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  9849. if (res != devices.end())
  9850. index = res - devices.begin();
  9851. else
  9852. devices.push_back(recipe->GetDevice());
  9853. }
  9854. packet->setDataByName("command_type", 0);
  9855. packet->setArrayLengthByName("num_recipes", recipes->size());
  9856. int stringsize = 0;
  9857. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  9858. recipe = itr->second;
  9859. int32 myid = recipe->GetID();
  9860. int8 rlevel = recipe->GetLevel();
  9861. int8 even = level - level * .05 + .5;
  9862. int8 easymin = level - level * .25 + .5;
  9863. int8 veasymin = level - level * .35 + .5;
  9864. if (rlevel > level )
  9865. packet->setArrayDataByName("tier", 4, i);
  9866. else if ((rlevel <= level) & (rlevel >= even))
  9867. packet->setArrayDataByName("tier", 3, i);
  9868. else if ((rlevel <= even) & (rlevel >= easymin))
  9869. packet->setArrayDataByName("tier", 2, i);
  9870. else if ((rlevel <= easymin) & (rlevel >= veasymin))
  9871. packet->setArrayDataByName("tier", 1, i);
  9872. else if ((rlevel <= veasymin) & (rlevel >= 0))
  9873. packet->setArrayDataByName("tier", 0, i);
  9874. if (rlevel == 2)
  9875. int xxx = 1;
  9876. packet->setArrayDataByName("recipe_id", myid, i);
  9877. packet->setArrayDataByName("level", recipe->GetLevel(), i);
  9878. packet->setArrayDataByName("unknown1", recipe->GetLevel(), i);
  9879. packet->setArrayDataByName("icon", recipe->GetIcon(), i);
  9880. packet->setArrayDataByName("classes", recipe->GetClasses(), i);
  9881. packet->setArrayDataByName("technique", recipe->GetTechnique(), i);
  9882. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), i);
  9883. auto recipe_device = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  9884. if (recipe_device != devices.end())
  9885. packet->setArrayDataByName("device_type", recipe_device - devices.begin(), i);
  9886. else
  9887. {//TODO error should never get here
  9888. }
  9889. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), i);
  9890. packet->setArrayDataByName("recipe_name", recipe->GetName(), i);
  9891. packet->setArrayDataByName("recipe_book", recipe->GetBook(), i);
  9892. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), i);
  9893. i++;
  9894. }
  9895. //packet->PrintPacket();
  9896. EQ2Packet* pack = packet->serialize();
  9897. QueuePacket(pack);
  9898. safe_delete(packet);
  9899. SetRecipeListSent(true);
  9900. }
  9901. void Client::ShowRecipeBook() {
  9902. PacketStruct* packet = 0;
  9903. Spawn* target = 0;
  9904. int index = 0;
  9905. if (!(target = player->GetTarget())) {
  9906. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have a tradeskill device targeted");
  9907. return;
  9908. }
  9909. if (!target->IsObject()) {
  9910. return;
  9911. }
  9912. if (!(packet = configReader.getStruct("WS_ShowRecipeBook", version))) {
  9913. return;
  9914. }
  9915. packet->setDataByName("device", target->GetName());
  9916. packet->setDataByName("unknown1", 1);
  9917. auto res = std::find(devices.begin(), devices.end(), target->GetName());
  9918. if (res != devices.end()){
  9919. index = res - devices.begin();
  9920. int32 deviceID = 0;
  9921. deviceID |= 1UL << index;
  9922. //LogWrite(TRADESKILL__ERROR, 0, "Tradeskills", "GetDeviceID() = %u, deviceID = %u", ((Object*)target)->GetDeviceID(), deviceID);
  9923. packet->setDataByName("unknown2", devices.size());
  9924. packet->setDataByName("unknown3", deviceID);
  9925. }
  9926. else
  9927. packet->setDataByName("unknown2", devices.size());
  9928. QueuePacket(packet->serialize());
  9929. safe_delete(packet);
  9930. }
  9931. void Client::SendTitleUpdate() {
  9932. // must call release read lock before leaving function on GetPlayerTitles
  9933. vector<Title*>* titles = player->GetPlayerTitles()->GetAllTitles();
  9934. vector<Title*>::iterator itr;
  9935. Title* title;
  9936. sint32 i = 0;
  9937. sint32 prefix_index = database.GetCharPrefixIndex(GetCharacterID(), player);
  9938. sint32 suffix_index = database.GetCharSuffixIndex(GetCharacterID(), player);
  9939. PacketStruct* packet = configReader.getStruct("WS_TitleUpdate", GetVersion());
  9940. if (packet) {
  9941. packet->setArrayLengthByName("num_titles", titles->size());
  9942. for (itr = titles->begin(); itr != titles->end(); itr++) {
  9943. title = *itr;
  9944. packet->setArrayDataByName("title", title->GetName(), i);
  9945. packet->setArrayDataByName("prefix", title->GetPrefix(), i);
  9946. i++;
  9947. }
  9948. packet->setDataByName("current_prefix", prefix_index);
  9949. packet->setDataByName("current_suffix", suffix_index);
  9950. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  9951. #if EQDEBUG >= 9
  9952. packet->PrintPacket();
  9953. #endif
  9954. QueuePacket(packet->serialize());
  9955. safe_delete(packet);
  9956. SendUpdateTitles(prefix_index, suffix_index);
  9957. }
  9958. player->GetPlayerTitles()->ReleaseReadLock();
  9959. }
  9960. void Client::SendUpdateTitles(sint32 prefix, sint32 suffix) {
  9961. Title* suffix_title = 0;
  9962. Title* prefix_title = 0;
  9963. if (suffix != -1) {
  9964. suffix_title = player->GetPlayerTitles()->GetTitle(suffix);
  9965. if(suffix_title)
  9966. strcpy(player->appearance.suffix_title, suffix_title->GetName());
  9967. }
  9968. else
  9969. memset(player->appearance.suffix_title, 0, strlen(player->appearance.suffix_title));
  9970. if (prefix != -1) {
  9971. prefix_title = player->GetPlayerTitles()->GetTitle(prefix);
  9972. if(prefix_title)
  9973. strcpy(player->appearance.prefix_title, prefix_title->GetName());
  9974. }
  9975. else
  9976. memset(player->appearance.prefix_title, 0, strlen(player->appearance.prefix_title));
  9977. current_zone->SendUpdateTitles(this, suffix_title, prefix_title);
  9978. }
  9979. void Client::SendLanguagesUpdate(int32 id, bool setlang) {
  9980. list<Language*>* languages = player->GetPlayerLanguages()->GetAllLanguages();
  9981. list<Language*>::iterator itr;
  9982. Language* language;
  9983. int32 i = 0;
  9984. if(setlang==1){
  9985. GetPlayer()->SetCurrentLanguage(id);
  9986. }
  9987. PacketStruct* packet = configReader.getStruct("WS_Languages", GetVersion());
  9988. if (packet) {
  9989. packet->setArrayLengthByName("num_languages", languages->size());
  9990. for (itr = languages->begin(); itr != languages->end(); itr++) {
  9991. language = *itr;
  9992. packet->setArrayDataByName("language_id", language->GetID(), i);
  9993. i++;
  9994. }
  9995. packet->setDataByName("current_language", id);
  9996. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  9997. #if EQDEBUG >= 9
  9998. packet->PrintPacket();
  9999. #endif
  10000. QueuePacket(packet->serialize());
  10001. safe_delete(packet);
  10002. }
  10003. }
  10004. void Client::SendPetOptionsWindow(const char* pet_name, int8 type) {
  10005. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  10006. if (packet) {
  10007. if (pet_name)
  10008. packet->setDataByName("pet_name", pet_name);
  10009. if (player->GetInfoStruct()->get_pet_behavior() & 1)
  10010. packet->setDataByName("protect_master", 1);
  10011. if (player->GetInfoStruct()->get_pet_behavior() & 2)
  10012. packet->setDataByName("protect_self", 1);
  10013. if (player->GetInfoStruct()->get_pet_movement() == 2)
  10014. packet->setDataByName("stay_follow_toggle", 1);
  10015. packet->setDataByName("pet_type", type);
  10016. QueuePacket(packet->serialize());
  10017. }
  10018. safe_delete(packet);
  10019. }
  10020. bool Client::IsCrafting() {
  10021. return current_zone->GetTradeskillMgr()->IsClientCrafting(this);
  10022. }
  10023. void Client::SendBiography() {
  10024. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  10025. if (packet) {
  10026. char biography[512];
  10027. if(player->GetInfoStruct()->get_biography().size() < 1)
  10028. {
  10029. safe_delete(packet);
  10030. return;
  10031. }
  10032. else
  10033. {
  10034. int16 size = player->GetInfoStruct()->get_biography().size();
  10035. if(size>511)
  10036. size = 511;
  10037. strncpy(biography, player->GetInfoStruct()->get_biography().c_str(), player->GetInfoStruct()->get_biography().size());
  10038. biography[player->GetInfoStruct()->get_biography().size()] = '\0';
  10039. }
  10040. packet->setDataByName("biography", biography);
  10041. QueuePacket(packet->serialize());
  10042. }
  10043. safe_delete(packet);
  10044. }
  10045. PendingResurrection* Client::GetCurrentRez() {
  10046. return &current_rez;
  10047. }
  10048. Mutex* Client::GetResurrectMutex() {
  10049. return &m_resurrect;
  10050. }
  10051. void Client::SendResurrectionWindow() {
  10052. Spawn* caster = current_rez.caster;
  10053. if (!caster || !player)
  10054. return;
  10055. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  10056. if (!packet)
  10057. return;
  10058. char* tmp = new char[512];
  10059. sprintf(tmp, "%s would like to cast '%s' on you. Do you accept?", caster->GetName(), current_rez.spell_name.c_str());
  10060. packet->setMediumStringByName("text", tmp);
  10061. packet->setMediumStringByName("accept_text", "Yes");
  10062. packet->setMediumStringByName("cancel_text", "No");
  10063. sprintf(tmp, "accept_resurrection %u", player->GetID());
  10064. packet->setMediumStringByName("accept_command", tmp);
  10065. sprintf(tmp, "decline_resurrection %u", player->GetID());
  10066. packet->setMediumStringByName("cancel_command", tmp);
  10067. packet->setDataByName("time", current_rez.expire_timer->GetRemainingTime() / 1000);
  10068. QueuePacket(packet->serialize());
  10069. safe_delete(packet);
  10070. safe_delete_array(tmp);
  10071. }
  10072. void Client::AcceptResurrection() {
  10073. Spawn* caster = current_rez.caster;
  10074. if (!player || !caster)
  10075. return;
  10076. if (player->Alive())
  10077. return;
  10078. if ((caster->GetZone() != player->GetZone()) || (current_rez.range > 0 && player->GetDistance(caster) > current_rez.range)) {
  10079. SimpleMessage(CHANNEL_COLOR_YELLOW, "The caster must be nearby to complete the spell.");
  10080. SendResurrectionWindow();
  10081. return;
  10082. }
  10083. player->GetZone()->ResurrectSpawn(player, this);
  10084. current_rez.should_delete = true;
  10085. }
  10086. void Client::SetPendingLastName(string last_name) {
  10087. pending_last_name = new string;
  10088. pending_last_name->assign(last_name);
  10089. }
  10090. string* Client::GetPendingLastName() {
  10091. return pending_last_name;
  10092. }
  10093. void Client::RemovePendingLastName() {
  10094. safe_delete(pending_last_name);
  10095. }
  10096. void Client::SendLastNameConfirmation() {
  10097. if (!pending_last_name)
  10098. return;
  10099. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  10100. if (packet) {
  10101. char* text = new char[128];
  10102. sprintf(text, "Are you sure you want your last name to be \"%s\"?", pending_last_name->c_str());
  10103. packet->setDataByName("text", text);
  10104. packet->setDataByName("accept_text", "Yes");
  10105. packet->setDataByName("accept_command", "confirmedlastname");
  10106. packet->setDataByName("cancel_text", "No");
  10107. packet->setDataByName("max_length", 50);
  10108. packet->setDataByName("unknown4", 1);
  10109. packet->setDataByName("unknown5", 1);
  10110. QueuePacket(packet->serialize());
  10111. safe_delete(packet);
  10112. safe_delete_array(text);
  10113. }
  10114. }
  10115. void Client::AddQuestTimer(int32 quest_id) {
  10116. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  10117. quest_timers.push_back(quest_id);
  10118. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  10119. }
  10120. void Client::RemoveQuestTimer(int32 quest_id) {
  10121. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  10122. vector<int32>::iterator itr;
  10123. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  10124. if ((*itr) == quest_id) {
  10125. quest_timers.erase(itr);
  10126. break;
  10127. }
  10128. }
  10129. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  10130. }
  10131. void Client::SavePlayerImages() {
  10132. LogWrite(CCLIENT__DEBUG, 0, "Client", "Saving %s image for player %s (%u)", (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL ? "paperdoll" : "headshot"), GetPlayer()->GetName(), GetCharacterID());
  10133. // Save the paperdoll image if the server allows it
  10134. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL && rule_manager.GetGlobalRule(R_World, SavePaperdollImage)->GetBool())
  10135. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  10136. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_HEAD) {
  10137. // Save the head shot if the server allows it
  10138. if (rule_manager.GetGlobalRule(R_World, SaveHeadshotImage)->GetBool())
  10139. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  10140. // Send the head shot to the login server
  10141. if (rule_manager.GetGlobalRule(R_World, SendPaperdollImagesToLogin)->GetBool()) {
  10142. int32 size = incoming_paperdoll.current_size_bytes + CHARPICSTRUCT_MINSIZE;
  10143. ServerPacket* packet = new ServerPacket(ServerOP_CharacterPicture, size);
  10144. memset(packet->pBuffer, 0, size);
  10145. CharPictureUpdate_Struct* pic = (CharPictureUpdate_Struct*)packet->pBuffer;
  10146. pic->account_id = GetAccountID();
  10147. pic->char_id = GetCharacterID();
  10148. pic->pic_size = (int16)incoming_paperdoll.current_size_bytes;
  10149. memcpy(pic->pic, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  10150. loginserver.SendPacket(packet);
  10151. safe_delete(packet);
  10152. }
  10153. }
  10154. safe_delete_array(incoming_paperdoll.image_bytes);
  10155. incoming_paperdoll.current_size_bytes = 0;
  10156. }
  10157. void Client::EndAutoMount() {
  10158. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  10159. if (packet) {
  10160. packet->setDataByName("parameter1", 128);
  10161. packet->setDataByName("parameter2", 64);
  10162. packet->setDataByName("value", 1);
  10163. QueuePacket(packet->serialize());
  10164. safe_delete(packet);
  10165. }
  10166. packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  10167. if (packet) {
  10168. packet->setDataByName("parameter3", 4);
  10169. packet->setDataByName("parameter5", 2);
  10170. packet->setDataByName("value", 0);
  10171. QueuePacket(packet->serialize());
  10172. safe_delete(packet);
  10173. }
  10174. packet = configReader.getStruct("WS_ClearForLanding", GetVersion());
  10175. if (packet) {
  10176. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  10177. QueuePacket(packet->serialize());
  10178. safe_delete(packet);
  10179. }
  10180. on_auto_mount = false;
  10181. player->SetMount(((Player*)player)->GetTempMount());
  10182. EQ2_Color mount_color = player->GetTempMountColor();
  10183. EQ2_Color saddle_color = player->GetTempMountSaddleColor();
  10184. player->SetMountColor(&mount_color);
  10185. player->SetMountSaddleColor(&saddle_color);
  10186. player->SetTempMount(0);
  10187. }
  10188. bool Client::EntityCommandPrecheck(Spawn* spawn, const char* command) {
  10189. const char* spawn_script = spawn->GetSpawnScript();
  10190. bool should_use_spawn = true;
  10191. if (spawn_script) {
  10192. lua_State* state = lua_interface->GetSpawnScript(spawn_script);
  10193. if (state) {
  10194. Mutex* state_mutex = lua_interface->GetSpawnScriptMutex(spawn_script);
  10195. if (state_mutex)
  10196. state_mutex->writelock(__FUNCTION__, __LINE__);
  10197. lua_getglobal(state, "can_use_command");
  10198. if (lua_isfunction(state, -1)) {
  10199. lua_interface->SetSpawnValue(state, spawn);
  10200. lua_interface->SetSpawnValue(state, GetPlayer());
  10201. lua_interface->SetStringValue(state, command ? command : "");
  10202. if (lua_pcall(state, 3, 1, 0) == 0) {
  10203. should_use_spawn = lua_interface->GetBooleanValue(state, 1);
  10204. }
  10205. }
  10206. lua_interface->ResetFunctionStack(state);
  10207. if (state_mutex)
  10208. state_mutex->releasewritelock(__FUNCTION__, __LINE__);
  10209. }
  10210. }
  10211. return should_use_spawn;
  10212. }
  10213. bool Client::IsCurrentTransmuteID(int32 req_id) {
  10214. return req_id == transmuteID;
  10215. }
  10216. void Client::SetTransmuteID(int32 trans_id) {
  10217. transmuteID = trans_id;
  10218. }
  10219. int32 Client::GetTransmuteID() {
  10220. return transmuteID;
  10221. }
  10222. bool Client::HandleNewLogin(int32 account_id, int32 access_code)
  10223. {
  10224. printf("HandleNewLogin: AcctID: %i AccessCode: %i\n", account_id, access_code);
  10225. ZoneAuthRequest* zar = zone_auth.GetAuth(account_id, access_code);
  10226. if (zar)
  10227. {
  10228. int32 charID = database.GetCharacterID(zar->GetCharacterName());
  10229. if (database.IsActiveQuery(charID))
  10230. {
  10231. delayedLogin = true;
  10232. delayedAccountID = account_id;
  10233. delayedAccessKey = access_code;
  10234. delayTimer.Start(500);
  10235. 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);
  10236. return true;
  10237. }
  10238. delayedLogin = false;
  10239. delayTimer.Disable();
  10240. firstlogin = zar->isFirstLogin();
  10241. SetReadyForSpawns(false);
  10242. ready_for_updates = false;
  10243. 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);
  10244. Client* client = zone_list.GetClientByCharName(zar->GetCharacterName());
  10245. if (client || database.loadCharacter(zar->GetCharacterName(), zar->GetAccountID(), this)) {
  10246. GetPlayer()->CalculateOfflineDebtRecovery(GetLastSavedTimeStamp());
  10247. GetPlayer()->vis_changed = false;
  10248. GetPlayer()->info_changed = false;
  10249. bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
  10250. if (pvp_allowed)
  10251. this->GetPlayer()->SetAttackable(1);
  10252. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  10253. if (client) {
  10254. if (client->getConnection())
  10255. client->getConnection()->SendDisconnect(true);
  10256. bool restore_ld_success = false;
  10257. if (client->GetCurrentZone() && !client->IsZoning()) {
  10258. //swap players, allowing the client to resume his LD'd player (ONLY if same version of the client)
  10259. if (client->GetVersion() == version) {
  10260. client->DisableSave();
  10261. client->ReplaceGroupClient(this);
  10262. Player* current_player = GetPlayer();
  10263. SetPlayer(client->GetPlayer());
  10264. GetPlayer()->SetClient(this);
  10265. GetPlayer()->SetReturningFromLD(true);
  10266. SetCharacterID(client->GetCharacterID());
  10267. SetAccountID(client->GetAccountID());
  10268. SetAdminStatus(client->GetAdminStatus());
  10269. SetCurrentZone(GetPlayer()->GetZone());
  10270. client->SetPlayer(current_player);
  10271. GetPlayer()->ResetSavedSpawns();
  10272. restore_ld_success = true;
  10273. char tmpldname[128];
  10274. snprintf(tmpldname, 128, "%s Linkdead",GetPlayer()->GetName());
  10275. client->GetPlayer()->SetName(tmpldname, false);
  10276. }
  10277. ZoneServer* tmpZone = client->GetCurrentZone();
  10278. tmpZone->RemoveClientImmediately(client);
  10279. }
  10280. if(!restore_ld_success && !database.loadCharacter(zar->GetCharacterName(), zar->GetAccountID(), this)) {
  10281. LogWrite(ZONE__ERROR, 0, "Zone", "Error reloading LD character and loading DB character: %s", player->GetName());
  10282. ClientPacketFunctions::SendLoginDenied(this);
  10283. Disconnect();
  10284. return false;
  10285. }
  10286. }
  10287. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  10288. if (!GetCurrentZone()) {
  10289. LogWrite(ZONE__ERROR, 0, "Zone", "Error loading zone for character: %s", player->GetName());
  10290. ClientPacketFunctions::SendLoginDenied(this);
  10291. Disconnect();
  10292. return false;
  10293. }
  10294. else if (EQOpcodeManager.count(GetOpcodeVersion(version)) > 0 && getConnection()) {
  10295. getConnection()->SetClientVersion(version);
  10296. GetCurrentZone()->SetSpawnStructs(this);
  10297. connected_to_zone = true;
  10298. client_list.Remove(this); //remove from master client list
  10299. GetCurrentZone()->AddClient(this); //add to zones client list
  10300. zone_list.AddClientToMap(player->GetName(), this);
  10301. // 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.
  10302. if(GetCurrentZone()->IsLoading()) {
  10303. new_client_login = NewLoginState::LOGIN_DELAYED;
  10304. }
  10305. else {
  10306. new_client_login = NewLoginState::LOGIN_ALLOWED;
  10307. }
  10308. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  10309. if (zone_script && lua_interface)
  10310. lua_interface->RunZoneScript(zone_script, "new_client", GetCurrentZone(), GetPlayer());
  10311. }
  10312. else {
  10313. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  10314. version = 0;
  10315. ClientPacketFunctions::SendLoginDenied(this);
  10316. Disconnect();
  10317. return false;
  10318. }
  10319. }
  10320. else {
  10321. LogWrite(WORLD__ERROR, 0, "World", "Could not load character '%s' with account id of: %u", zar->GetCharacterName(), zar->GetAccountID());
  10322. ClientPacketFunctions::SendLoginDenied(this);
  10323. Disconnect();
  10324. return false;
  10325. }
  10326. zone_auth.RemoveAuth(zar);
  10327. }
  10328. else
  10329. {
  10330. LogWrite(WORLD__ERROR, 0, "World", "Invalid ZoneAuthRequest, disconnecting client.");
  10331. Disconnect();
  10332. return false;
  10333. }
  10334. return true;
  10335. }
  10336. void Client::SendSpawnChanges(set<Spawn*>& spawns) {
  10337. if (!IsReadyForUpdates())
  10338. return;
  10339. map<int32, SpawnData> info_changes;
  10340. map<int32, SpawnData> pos_changes;
  10341. map<int32, SpawnData> vis_changes;
  10342. map<int32, SpawnData> empty_changes;
  10343. int32 info_size = 0;
  10344. int32 pos_size = 0;
  10345. int32 vis_size = 0;
  10346. int count = 0;
  10347. for (const auto& spawn : spawns) {
  10348. int16 index = GetPlayer()->GetIndexForSpawn(spawn);
  10349. if (index == 0 || !GetPlayer()->WasSentSpawn(spawn->GetID()))
  10350. continue;
  10351. if(GetPlayer() == spawn && GetVersion() <= 284) { // stopped self client/player warping in the EQ2 release disc (Beta), don't send yourself in bulk spawn updates
  10352. continue;
  10353. }
  10354. int16 tmp_info_size = 0;
  10355. int16 tmp_pos_size = 0;
  10356. int16 tmp_vis_size = 0;
  10357. if (spawn->vis_changed)
  10358. {
  10359. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion(), &tmp_vis_size);
  10360. if (vis_change) {
  10361. SpawnData data;
  10362. data.spawn = spawn;
  10363. data.data = vis_change;
  10364. data.size = tmp_vis_size;
  10365. map<int32, SpawnData> tmp_vis_changes;
  10366. tmp_vis_changes[index] = data;
  10367. map<int32, SpawnData> tmp_info_changes;
  10368. map<int32, SpawnData> tmp_pos_changes;
  10369. if (spawn->info_changed) {
  10370. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion(), &tmp_info_size);
  10371. if (info_change) {
  10372. SpawnData data;
  10373. data.spawn = spawn;
  10374. data.data = info_change;
  10375. data.size = tmp_info_size;
  10376. tmp_info_changes[index] = data;
  10377. }
  10378. }
  10379. if (spawn->position_changed) {
  10380. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion(), &tmp_pos_size);
  10381. if (pos_change) {
  10382. SpawnData data;
  10383. data.spawn = spawn;
  10384. data.data = pos_change;
  10385. data.size = tmp_pos_size;
  10386. tmp_pos_changes[index] = data;
  10387. }
  10388. }
  10389. MakeSpawnChangePacket(tmp_info_changes, tmp_pos_changes, tmp_vis_changes, tmp_info_size, tmp_pos_size, data.size);
  10390. for (auto& kv : tmp_info_changes) {
  10391. safe_delete_array(kv.second.data);
  10392. }
  10393. for (auto& kv : tmp_pos_changes) {
  10394. safe_delete_array(kv.second.data);
  10395. }
  10396. for (auto& kv : tmp_vis_changes) {
  10397. safe_delete_array(kv.second.data);
  10398. }
  10399. continue;
  10400. }
  10401. }
  10402. if (spawn->info_changed) {
  10403. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion(), &tmp_info_size);
  10404. if (info_change) {
  10405. SpawnData data;
  10406. data.spawn = spawn;
  10407. data.data = info_change;
  10408. data.size = tmp_info_size;
  10409. info_size += tmp_info_size;
  10410. info_changes[index] = data;
  10411. }
  10412. count++;
  10413. }
  10414. if (spawn->position_changed) {
  10415. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion(), &tmp_pos_size);
  10416. if (pos_change) {
  10417. SpawnData data;
  10418. data.spawn = spawn;
  10419. data.data = pos_change;
  10420. data.size = tmp_pos_size;
  10421. pos_size += tmp_pos_size;
  10422. pos_changes[index] = data;
  10423. }
  10424. count++;
  10425. }
  10426. if (spawn->vis_changed) {
  10427. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion(), &tmp_vis_size);
  10428. if (vis_change) {
  10429. SpawnData data;
  10430. data.spawn = spawn;
  10431. data.data = vis_change;
  10432. data.size = tmp_vis_size;
  10433. vis_size += tmp_vis_size;
  10434. vis_changes[index] = data;
  10435. }
  10436. count++;
  10437. }
  10438. }
  10439. if (info_size == 0 && pos_size == 0 && vis_size == 0) {
  10440. return;
  10441. }
  10442. MakeSpawnChangePacket(info_changes, pos_changes, vis_changes, info_size, pos_size, vis_size);
  10443. for (auto& kv : info_changes) {
  10444. safe_delete_array(kv.second.data);
  10445. }
  10446. for (auto& kv : pos_changes) {
  10447. safe_delete_array(kv.second.data);
  10448. }
  10449. for (auto& kv : vis_changes) {
  10450. safe_delete_array(kv.second.data);
  10451. }
  10452. }
  10453. 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)
  10454. {
  10455. static const int8 oversized = 255;
  10456. int16 opcode_val = 0;
  10457. if (EQOpcodeManager.count(GetOpcodeVersion(version)) != 0) {
  10458. opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd);
  10459. }
  10460. int32 size = info_size + pos_size + vis_size + 8;
  10461. size += CheckOverLoadSize(info_size);
  10462. size += CheckOverLoadSize(pos_size);
  10463. size += CheckOverLoadSize(vis_size);
  10464. if (version <= 373 && size >= 255) {//1 byte to 3 for overloaded val
  10465. size += 2;
  10466. }
  10467. else if (version >= 374)
  10468. size += 3;
  10469. uchar* tmp = new uchar[size];
  10470. uchar* ptr = tmp;
  10471. memset(tmp, 0, size);
  10472. if (version <= 373) {
  10473. if (size >= 255) {
  10474. size -= 3;
  10475. memcpy(ptr, &oversized, sizeof(int8));
  10476. ptr += sizeof(int8);
  10477. memcpy(ptr, &size, sizeof(int16));
  10478. ptr += sizeof(int16);
  10479. size += 3;
  10480. }
  10481. else {
  10482. size -= 1;
  10483. memcpy(ptr, &size, sizeof(int8));
  10484. ptr += sizeof(int8);
  10485. size += 1;
  10486. }
  10487. }
  10488. else {
  10489. size -= 4;
  10490. memcpy(ptr, &size, sizeof(int32));
  10491. ptr += sizeof(int32);
  10492. size += 4;
  10493. }
  10494. memcpy(ptr, &oversized, sizeof(int8));
  10495. ptr += sizeof(int8);
  10496. memcpy(ptr, &opcode_val, sizeof(int16));
  10497. ptr += sizeof(int16);
  10498. int32 current_time = Timer::GetCurrentTime2();
  10499. memcpy(ptr, &current_time, sizeof(int32));
  10500. ptr += sizeof(int32);
  10501. ptr += DoOverLoad(info_size, ptr);
  10502. for (const auto& kv : info_changes) {
  10503. auto info = kv.second;
  10504. memcpy(ptr, info.data, info.size);
  10505. ptr += info.size;
  10506. }
  10507. ptr += DoOverLoad(pos_size, ptr);
  10508. for (const auto& kv : pos_changes) {
  10509. auto pos = kv.second;
  10510. memcpy(ptr, pos.data, pos.size);
  10511. ptr += pos.size;
  10512. }
  10513. ptr += DoOverLoad(vis_size, ptr);
  10514. for (const auto& kv : vis_changes) {
  10515. auto vis = kv.second;
  10516. memcpy(ptr, vis.data, vis.size);
  10517. ptr += vis.size;
  10518. }
  10519. EQ2Packet* packet = new EQ2Packet(OP_ClientCmdMsg, tmp, size);
  10520. if (packet) {
  10521. /*char blah[64];
  10522. snprintf(blah, 64, "Sending %i", current_time);
  10523. SimpleMessage(4, blah);*/
  10524. QueuePacket(packet);
  10525. }
  10526. delete[] tmp;
  10527. }
  10528. void Client::SendHailCommand(Spawn* spawn)
  10529. {
  10530. // hardcoded 'hail' entity commands
  10531. switch (spawn->secondary_command_list_id)
  10532. {
  10533. case 9:
  10534. case 1262:
  10535. case 1265:
  10536. case 1267:
  10537. {
  10538. EQ2_16BitString* command = new EQ2_16BitString();
  10539. command->data = "";
  10540. command->size = 0;
  10541. commands.Process(COMMAND_HAIL, command, this, spawn);
  10542. safe_delete(command);
  10543. break;
  10544. }
  10545. }
  10546. }
  10547. void Client::SendDefaultCommand(Spawn* spawn, const char* command, float distance)
  10548. {
  10549. if (GetPlayer()->WasSentSpawn(spawn->GetID())) {
  10550. PacketStruct* packet = configReader.getStruct("WS_SetDefaultCommand", GetVersion());
  10551. if (packet) {
  10552. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  10553. packet->setMediumStringByName("command_name", command);
  10554. packet->setDataByName("distance", distance);
  10555. QueuePacket(packet->serialize());
  10556. safe_delete(packet);
  10557. }
  10558. }
  10559. }
  10560. bool Client::HandleHouseEntityCommands(Spawn* spawn, int32 spawnid, string command)
  10561. {
  10562. if (GetCurrentZone()->GetInstanceType() != PERSONAL_HOUSE_INSTANCE)
  10563. return false;
  10564. if (command == "house_spawn_examine")
  10565. {
  10566. uint32 itemID = spawn->GetPickupItemID();
  10567. if (itemID)
  10568. {
  10569. Item* item = master_item_list.GetItem(itemID);
  10570. if (item)
  10571. {
  10572. EQ2Packet* app = item->serialize(GetVersion(), true, GetPlayer());
  10573. //DumpPacket(app);
  10574. QueuePacket(app);
  10575. }
  10576. }
  10577. return true;
  10578. }
  10579. return false;
  10580. }
  10581. bool Client::PopulateHouseSpawn(PacketStruct* place_object)
  10582. {
  10583. if (GetTempPlacementSpawn())
  10584. {
  10585. Spawn* tmp = GetTempPlacementSpawn();
  10586. int32 spawn_group_id = database.GetNextSpawnLocation();
  10587. tmp->SetSpawnLocationID(spawn_group_id);
  10588. float newHeading = place_object->getType_float_ByName("heading") + 180;
  10589. int32 spawnDBID = 0;
  10590. if (GetCurrentZone()->house_object_database_lookup.count(tmp->GetModelType()) > 0)
  10591. {
  10592. spawnDBID = GetCurrentZone()->house_object_database_lookup.Get(tmp->GetModelType());
  10593. tmp->SetDatabaseID(spawnDBID);
  10594. }
  10595. else
  10596. {
  10597. spawnDBID = database.FindHouseInstanceSpawn(tmp);
  10598. if (spawnDBID)
  10599. {
  10600. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), spawnDBID);
  10601. tmp->SetDatabaseID(spawnDBID);
  10602. }
  10603. }
  10604. tmp->SetX(place_object->getType_float_ByName("x"));
  10605. tmp->SetY(place_object->getType_float_ByName("y"));
  10606. tmp->SetZ(place_object->getType_float_ByName("z"));
  10607. tmp->SetHeading(newHeading);
  10608. tmp->SetSpawnOrigX(tmp->GetX());
  10609. tmp->SetSpawnOrigY(tmp->GetY());
  10610. tmp->SetSpawnOrigZ(tmp->GetZ());
  10611. tmp->SetSpawnOrigHeading(tmp->GetHeading());
  10612. database.SaveSpawnInfo(tmp);
  10613. database.SaveSpawnEntry(tmp, "houseplacement", 100, 0, 0, 0);
  10614. if (!spawnDBID)
  10615. {
  10616. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), tmp->GetDatabaseID());
  10617. // we need to copy as to not delete the ZoneServer object_list entry this on house item pickup
  10618. GetCurrentZone()->AddObject(tmp->GetDatabaseID(), ((Object*)tmp)->Copy());
  10619. }
  10620. return true;
  10621. }
  10622. return false;
  10623. }
  10624. bool Client::PopulateHouseSpawnFinalize()
  10625. {
  10626. if (GetTempPlacementSpawn())
  10627. {
  10628. Spawn* tmp = GetTempPlacementSpawn();
  10629. GetCurrentZone()->AddSpawn(tmp);
  10630. GetCurrentZone()->SendSpawnChanges(tmp, this);
  10631. SetTempPlacementSpawn(nullptr);
  10632. int32 uniqueID = GetPlacementUniqueItemID();
  10633. Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  10634. tmp->SetPickupItemID(uniqueItem->details.item_id);
  10635. tmp->SetPickupUniqueItemID(uniqueID);
  10636. if (uniqueItem)
  10637. {
  10638. if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE)
  10639. {
  10640. Query query;
  10641. 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);
  10642. }
  10643. if(uniqueItem->GetItemScript() &&
  10644. lua_interface->RunItemScript(uniqueItem->GetItemScript(), "placed", uniqueItem, GetPlayer(), tmp))
  10645. {
  10646. uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  10647. }
  10648. if(uniqueItem) {
  10649. database.DeleteItem(GetCharacterID(), uniqueItem, 0);
  10650. GetPlayer()->item_list.RemoveItem(uniqueItem, true);
  10651. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  10652. }
  10653. SetPlacementUniqueItemID(0);
  10654. }
  10655. return true;
  10656. }
  10657. return false;
  10658. }
  10659. void Client::SendMoveObjectMode(Spawn* spawn, uint8 placementMode, float unknown2_3)
  10660. {
  10661. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", GetVersion());
  10662. packet->setDataByName("placement_mode", placementMode);
  10663. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  10664. packet->setDataByName("model_type", spawn->GetModelType());
  10665. packet->setDataByName("unknown", 1); //size
  10666. packet->setDataByName("unknown2", 1); //size 2
  10667. packet->setDataByName("unknown2", .5, 1); //size 3
  10668. packet->setDataByName("unknown2", 3, 2);
  10669. packet->setDataByName("unknown2", unknown2_3, 3);
  10670. packet->setDataByName("max_distance", 500);
  10671. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  10672. QueuePacket(packet->serialize());
  10673. safe_delete(packet);
  10674. }
  10675. void Client::SendFlightAutoMount(int32 path_id, int16 mount_id, int8 mount_red_color, int8 mount_green_color, int8 mount_blue_color)
  10676. {
  10677. SetPendingFlightPath(path_id);
  10678. ((Player*)player)->SetTempMount(((Entity*)player)->GetMount());
  10679. ((Player*)player)->SetTempMountColor(((Entity*)player)->GetMountColor());
  10680. ((Player*)player)->SetTempMountSaddleColor(((Entity*)player)->GetMountSaddleColor());
  10681. PacketStruct* packet = configReader.getStruct("WS_ReadyForTakeOff", GetVersion());
  10682. if (packet) {
  10683. QueuePacket(packet->serialize());
  10684. safe_delete(packet);
  10685. }
  10686. if (mount_id)
  10687. ((Entity*)GetPlayer())->SetMount(mount_id, mount_red_color, mount_green_color, mount_blue_color);
  10688. }
  10689. void Client::SendShowBook(Spawn* sender, string title, int8 language, int8 num_pages, ...)
  10690. {
  10691. if (!sender)
  10692. {
  10693. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  10694. return;
  10695. }
  10696. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  10697. if (!packet) {
  10698. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  10699. return;
  10700. }
  10701. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  10702. packet->setDataByName("book_title", title.c_str());
  10703. packet->setDataByName("book_type", "simple");
  10704. packet->setDataByName("unknown2", 1);
  10705. if(language > 0 && !GetPlayer()->HasLanguage(language))
  10706. packet->setDataByName("language", language);
  10707. if (GetVersion() > 561)
  10708. packet->setDataByName("unknown5", 1, 4);
  10709. packet->setArrayLengthByName("num_pages", num_pages);
  10710. va_list args;
  10711. va_start(args, num_pages);
  10712. std::string endString("");
  10713. for (int8 p = 0; p < num_pages; p++)
  10714. {
  10715. std::string page = va_arg(args, string);
  10716. switch (GetVersion())
  10717. {
  10718. // release client
  10719. case 283:
  10720. case 373: // trial isle client
  10721. {
  10722. endString.append(page);
  10723. break;
  10724. }
  10725. // DoF trial
  10726. case 546:
  10727. case 561:
  10728. {
  10729. if (p == 0)
  10730. packet->setDataByName("cover_page", page.c_str());
  10731. else
  10732. packet->setArrayDataByName("page_text", page.c_str(), p - 1);
  10733. break;
  10734. }
  10735. // all other clients
  10736. default:
  10737. {
  10738. packet->setArrayDataByName("page_text", page.c_str(), p);
  10739. break;
  10740. }
  10741. }
  10742. }
  10743. if (GetVersion() <= 373)
  10744. {
  10745. packet->setDataByName("page_text", endString.c_str());
  10746. }
  10747. va_end(args);
  10748. QueuePacket(packet->serialize());
  10749. safe_delete(packet);
  10750. }
  10751. void Client::SendShowBook(Spawn* sender, string title, int8 language, vector<Item::BookPage*> pages)
  10752. {
  10753. if (!sender)
  10754. {
  10755. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  10756. return;
  10757. }
  10758. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  10759. if (!packet) {
  10760. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  10761. return;
  10762. }
  10763. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  10764. packet->setDataByName("book_title", title.c_str());
  10765. packet->setDataByName("book_type", "simple");
  10766. packet->setDataByName("unknown2", 1);
  10767. if(language > 0 && !GetPlayer()->HasLanguage(language))
  10768. packet->setDataByName("language", language);
  10769. if (GetVersion() > 561)
  10770. packet->setDataByName("unknown5", 1, 4);
  10771. packet->setArrayLengthByName("num_pages", pages.size());
  10772. std::string endString("");
  10773. for (int8 p = 0; p < pages.size(); p++)
  10774. {
  10775. Item::BookPage* page = pages[p];
  10776. std::string pageText = string(page->page_text.data);
  10777. switch (GetVersion())
  10778. {
  10779. // release client
  10780. case 283:
  10781. case 373: // trial isle client
  10782. {
  10783. endString.append(pageText);
  10784. break;
  10785. }
  10786. // DoF trial
  10787. case 546:
  10788. case 561:
  10789. {
  10790. if (p == 0)
  10791. packet->setDataByName("cover_page", pageText.c_str());
  10792. else
  10793. packet->setArrayDataByName("page_text", pageText.c_str(), p - 1);
  10794. break;
  10795. }
  10796. // all other clients
  10797. default:
  10798. {
  10799. int8 valign = int8(page->valign);
  10800. int8 halign = int8(page->halign);
  10801. packet->setArrayDataByName("page_text", pageText.c_str(), p);
  10802. packet->setArrayDataByName("page_text_valign", valign, p);
  10803. packet->setArrayDataByName("page_text_halign", halign, p);
  10804. break;
  10805. }
  10806. }
  10807. }
  10808. if (GetVersion() == 283)
  10809. {
  10810. packet->setDataByName("page_text", endString.c_str());
  10811. }
  10812. QueuePacket(packet->serialize());
  10813. safe_delete(packet);
  10814. }
  10815. void Client::ReplaceGroupClient(Client* new_client)
  10816. {
  10817. if (this->GetPlayer()->GetGroupMemberInfo())
  10818. {
  10819. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  10820. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  10821. if(group)
  10822. {
  10823. group->MGroupMembers.writelock();
  10824. rejoin_group_id = this->GetPlayer()->GetGroupMemberInfo()->group_id;
  10825. this->GetPlayer()->GetGroupMemberInfo()->client = new_client;
  10826. this->GetPlayer()->GetGroupMemberInfo()->member = GetPlayer();
  10827. group->MGroupMembers.releasewritelock();
  10828. }
  10829. else
  10830. {
  10831. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  10832. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  10833. this->GetPlayer()->SetGroupMemberInfo(0);
  10834. }
  10835. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  10836. }
  10837. }
  10838. void Client::TempRemoveGroup()
  10839. {
  10840. if (this->GetPlayer()->GetGroupMemberInfo())
  10841. {
  10842. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  10843. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  10844. if(group)
  10845. {
  10846. group->MGroupMembers.writelock();
  10847. rejoin_group_id = this->GetPlayer()->GetGroupMemberInfo()->group_id;
  10848. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  10849. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  10850. this->GetPlayer()->SetGroupMemberInfo(0);
  10851. group->MGroupMembers.releasewritelock();
  10852. group->RemoveClientReference(this);
  10853. }
  10854. else
  10855. {
  10856. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  10857. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  10858. this->GetPlayer()->SetGroupMemberInfo(0);
  10859. }
  10860. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  10861. }
  10862. }
  10863. void Client::CreateMail(int32 charID, std::string fromName, std::string subjectName, std::string mailBody,
  10864. int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time)
  10865. {
  10866. Mail mail;
  10867. mail.mail_id = 0;
  10868. mail.already_read = 0;
  10869. mail.postage_cost = 0;
  10870. mail.attachment_cost = 0;
  10871. mail.save_needed = 1;
  10872. //uhh...mail has std::strings so
  10873. //memset(&mail,0,sizeof(Mail));
  10874. mail.player_to_id = charID;
  10875. mail.player_from = fromName;
  10876. mail.subject = subjectName;
  10877. mail.mail_body = mailBody;
  10878. mail.mail_type = mailType;
  10879. mail.coin_copper = copper;
  10880. mail.coin_silver = silver;
  10881. mail.coin_gold = gold;
  10882. mail.coin_plat = platinum;
  10883. mail.char_item_id = item_id;
  10884. mail.stack = stack_size;
  10885. mail.time_sent = time_sent;
  10886. mail.expire_time = expire_time;
  10887. database.SavePlayerMail(&mail);
  10888. }
  10889. void Client::CreateAndUpdateMail(std::string fromName, std::string subjectName, std::string mailBody,
  10890. int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time)
  10891. {
  10892. Mail* mail = new Mail();
  10893. mail->player_to_id = GetCharacterID();
  10894. mail->player_from = fromName;
  10895. mail->subject = subjectName;
  10896. mail->mail_body = mailBody;
  10897. mail->mail_type = mailType;
  10898. mail->coin_copper = copper;
  10899. mail->coin_silver = silver;
  10900. mail->coin_gold = gold;
  10901. mail->coin_plat = platinum;
  10902. mail->char_item_id = item_id;
  10903. mail->stack = stack_size;
  10904. mail->time_sent = time_sent;
  10905. mail->expire_time = expire_time;
  10906. mail->postage_cost = 0;
  10907. mail->save_needed = 1;
  10908. mail->already_read = 0;
  10909. database.SavePlayerMail(mail);
  10910. GetPlayer()->AddMail(mail);
  10911. }
  10912. void Client::SendEquipOrInvUpdateBySlot(int8 slot)
  10913. {
  10914. if(slot < NUM_SLOTS)
  10915. {
  10916. EQ2Packet* app = GetPlayer()->GetEquipmentList()->serialize(GetVersion(), GetPlayer());
  10917. if (app)
  10918. QueuePacket(app);
  10919. }
  10920. else
  10921. {
  10922. EQ2Packet* outapp = GetPlayer()->SendInventoryUpdate(GetVersion());
  10923. if (outapp)
  10924. QueuePacket(outapp);
  10925. }
  10926. }
  10927. void Client::QueueStateCommand(int32 spawn_player_id, int32 state)
  10928. {
  10929. if(spawn_player_id < 1)
  10930. return;
  10931. MQueueStateCmds.writelock();
  10932. queued_state_commands.insert(make_pair(spawn_player_id, state));
  10933. MQueueStateCmds.releasewritelock();
  10934. }
  10935. void Client::ProcessStateCommands()
  10936. {
  10937. if(!IsReadyForUpdates())
  10938. return;
  10939. MQueueStateCmds.writelock();
  10940. map<int32, int32>::iterator itr = queued_state_commands.begin();
  10941. for(; itr != queued_state_commands.end(); itr++)
  10942. ClientPacketFunctions::SendStateCommand(this, itr->first, itr->second);
  10943. queued_state_commands.clear();
  10944. MQueueStateCmds.releasewritelock();
  10945. }
  10946. void Client::PurgeItem(Item* item)
  10947. {
  10948. std::unique_lock lock(MConversation);
  10949. map<int32, Item*>::iterator itr;
  10950. for(itr = conversation_items.begin(); itr != conversation_items.end(); itr++)
  10951. {
  10952. if ( itr->second == item )
  10953. {
  10954. conversation_items.erase(itr);
  10955. break;
  10956. }
  10957. }
  10958. }
  10959. void Client::ConsumeFoodDrink(Item* item, int32 slot)
  10960. {
  10961. if(GetPlayer()->StopSaveSpellEffects())
  10962. return;
  10963. if(item) {
  10964. LogWrite(MISC__INFO, 1, "Command", "ItemID: %u, ItemName: %s ItemCount: %i ", item->details.item_id, item->name.c_str(), item->details.count);
  10965. if(item->GetItemScript() && lua_interface){
  10966. lua_interface->RunItemScript(item->GetItemScript(), "cast", item, GetPlayer());
  10967. if (slot == 22)
  10968. Message(CHANNEL_NARRATIVE, "You eat a %s.", item->name.c_str());
  10969. else
  10970. Message(CHANNEL_NARRATIVE, "You drink a %s.", item->name.c_str());
  10971. }
  10972. else {
  10973. Message(CHANNEL_NARRATIVE, "SERVER BUG! Item Script not assigned for consuming '%s'.", item->name.c_str());
  10974. return;
  10975. }
  10976. if (item->details.count > 1) {
  10977. item->details.count -= 1;
  10978. item->save_needed = true;
  10979. }
  10980. else {
  10981. database.DeleteItem(GetPlayer()->GetCharacterID(), item, "EQUIPPED");
  10982. GetPlayer()->GetEquipmentList()->RemoveItem(slot, true);
  10983. }
  10984. GetPlayer()->SetCharSheetChanged(true);
  10985. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  10986. if(GetVersion() <= 373) {
  10987. EQ2Packet* outapp = GetPlayer()->SendInventoryUpdate(GetVersion());
  10988. QueuePacket(outapp);
  10989. }
  10990. }
  10991. }
  10992. void Client::AwardCoins(int64 total_coins, std::string reason)
  10993. {
  10994. if (total_coins > 0) {
  10995. player->AddCoins(total_coins);
  10996. PlaySound("coin_cha_ching");
  10997. char tmp[64] = { 0 };
  10998. string message = "You receive ";
  10999. int32 val = 0;
  11000. if (total_coins >= 1000000) {
  11001. val = total_coins / 1000000;
  11002. total_coins -= 1000000 * val;
  11003. sprintf(tmp, "%u Platinum ", val);
  11004. message.append(tmp);
  11005. memset(tmp, 0, 64);
  11006. }
  11007. if (total_coins >= 10000) {
  11008. val = total_coins / 10000;
  11009. total_coins -= 10000 * val;
  11010. sprintf(tmp, "%u Gold ", val);
  11011. message.append(tmp);
  11012. memset(tmp, 0, 64);
  11013. }
  11014. if (total_coins >= 100) {
  11015. val = total_coins / 100;
  11016. total_coins -= 100 * val;
  11017. sprintf(tmp, "%u Silver ", val);
  11018. message.append(tmp);
  11019. memset(tmp, 0, 64);
  11020. }
  11021. if (total_coins > 0) {
  11022. sprintf(tmp, "%u Copper ", (int32)total_coins);
  11023. message.append(tmp);
  11024. }
  11025. message.append(reason);
  11026. int8 type = CHANNEL_LOOT;
  11027. SimpleMessage(type, message.c_str());
  11028. }
  11029. }
  11030. void Client::TriggerSpellSave()
  11031. {
  11032. int32 interval = rule_manager.GetGlobalRule(R_Spells, PlayerSpellSaveStateWaitInterval)->GetInt32();
  11033. // default to not have some bogus value in the rule
  11034. if(interval < 1)
  11035. interval = 100;
  11036. MSaveSpellStateMutex.lock();
  11037. if(!save_spell_state_timer.Enabled())
  11038. {
  11039. save_spell_state_time_bucket = 0;
  11040. save_spell_state_timer.Start(interval, true);
  11041. }
  11042. else
  11043. {
  11044. int32 elapsed_time = save_spell_state_timer.GetElapsedTime();
  11045. save_spell_state_time_bucket += elapsed_time;
  11046. int32 save_wait_cap = rule_manager.GetGlobalRule(R_Spells, PlayerSpellSaveStateCap)->GetInt32();
  11047. // default to not have some bogus value in the rule
  11048. if(save_wait_cap < interval)
  11049. save_wait_cap = interval+1;
  11050. if(save_spell_state_time_bucket >= save_wait_cap)
  11051. {
  11052. save_spell_state_timer.Trigger();
  11053. }
  11054. }
  11055. MSaveSpellStateMutex.unlock();
  11056. }
  11057. void Client::UpdateSentSpellList() {
  11058. MSpellDetails.readlock(__FUNCTION__, __LINE__);
  11059. std::map<int32, int32>::iterator itr;
  11060. for(itr = sent_spell_details.begin(); itr != sent_spell_details.end(); itr++) {
  11061. Spell* spell = master_spell_list.GetSpell(itr->first, itr->second);
  11062. EQ2Packet* app = spell->SerializeSpell(this, false, false);
  11063. QueuePacket(app);
  11064. }
  11065. MSpellDetails.releasereadlock(__FUNCTION__, __LINE__);
  11066. }
  11067. void Client::SetTempPlacementSpawn(Spawn* tmp) {
  11068. tempPlacementSpawn = tmp;
  11069. hasSentTempPlacementSpawn = false;
  11070. if(tempPlacementSpawn)
  11071. temp_placement_timer.Start();
  11072. else
  11073. temp_placement_timer.Disable();
  11074. }
  11075. void Client::SetPlayer(Player* new_player) {
  11076. if (player && player != new_player)
  11077. zone_list.RemoveClientFromMap(player->GetName(), this);
  11078. player = new_player;
  11079. player->SetClient(this);
  11080. }
  11081. bool Client::UseItem(Item* item, Spawn* target) {
  11082. if (item && item->GetItemScript()) {
  11083. int16 item_index = item->details.index;
  11084. if(!item->CheckFlag2(INDESTRUCTABLE) && item->generic_info.condition == 0) {
  11085. SimpleMessage(CHANNEL_COLOR_RED, "This item is broken and must be repaired at a mender before it can be used");
  11086. }
  11087. else if (item->CheckFlag(EVIL_ONLY) && GetPlayer()->GetAlignment() != ALIGNMENT_EVIL) {
  11088. Message(0, "%s requires an evil race.", item->name.c_str());
  11089. }
  11090. else if (item->CheckFlag(GOOD_ONLY) && GetPlayer()->GetAlignment() != ALIGNMENT_GOOD) {
  11091. Message(0, "%s requires a good race.", item->name.c_str());
  11092. }
  11093. else if (item->generic_info.max_charges == 0 || item->generic_info.max_charges == 0xFFFF) {
  11094. lua_interface->RunItemScript(item->GetItemScript(), "used", item, player, target);
  11095. return true;
  11096. }
  11097. else {
  11098. if (item->details.count > 0) {
  11099. std::string itemName = string(item->name);
  11100. int32 item_id = item->details.item_id;
  11101. sint64 flags = 0;
  11102. if(lua_interface->RunItemScript(item->GetItemScript(), "used", item, player, target, &flags) && flags >= 0)
  11103. {
  11104. //reobtain item make sure it wasn't removed
  11105. item = player->item_list.GetItemFromIndex(item_index);
  11106. if(!item) {
  11107. 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);
  11108. return true;
  11109. }
  11110. else if(!item->generic_info.display_charges && item->generic_info.max_charges == 1) {
  11111. Message(CHANNEL_NARRATIVE, "%s is out of charges. It has been removed.", item->name.c_str());
  11112. RemoveItem(item, 1); // end of a set of charges OR an item that uses a stack count of actual item quantity
  11113. return true;
  11114. }
  11115. else
  11116. {
  11117. item->details.count--; // charges
  11118. item->save_needed = true;
  11119. QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  11120. if(!item->details.count) {
  11121. Message(CHANNEL_NARRATIVE, "%s is out of charges. It has been removed.", item->name.c_str());
  11122. RemoveItem(item, 1); // end of a set of charges OR an item that uses a stack count of actual item quantity
  11123. }
  11124. return true;
  11125. }
  11126. }
  11127. else {
  11128. 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);
  11129. return true;
  11130. }
  11131. }
  11132. else
  11133. {
  11134. //reobtain item make sure it wasn't removed
  11135. item = player->item_list.GetItemFromIndex(item_index);
  11136. SimpleMessage(CHANNEL_COLOR_YELLOW, "Item is out of charges.");
  11137. if(item) {
  11138. 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);
  11139. }
  11140. }
  11141. }
  11142. }
  11143. return false;
  11144. }
  11145. void Client::SendPlayFlavor(Spawn* spawn, int8 language, VoiceOverStruct* non_garble,
  11146. VoiceOverStruct* garble, bool success, bool garble_success) {
  11147. VoiceOverStruct* resStruct = nullptr;
  11148. if(language == 0 || GetPlayer()->HasLanguage(language)) {
  11149. if(success) {
  11150. resStruct = non_garble;
  11151. }
  11152. }
  11153. else if(garble_success) {
  11154. resStruct = garble;
  11155. }
  11156. if(resStruct) {
  11157. 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);
  11158. }
  11159. }
  11160. void Client::SaveQuestRewardData(bool force_refresh) {
  11161. Query query;
  11162. if(force_refresh) {
  11163. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete from character_quest_rewards where char_id = %u",
  11164. GetCharacterID());
  11165. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete from character_quest_temporary_rewards where char_id = %u",
  11166. GetCharacterID());
  11167. }
  11168. vector<QuestRewardData*>::iterator itr;
  11169. vector<QuestRewardData*> tmp_quest_rewards;
  11170. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  11171. int index = 0;
  11172. for (itr = quest_pending_reward.begin(); itr != quest_pending_reward.end(); itr++) {
  11173. int32 questID = (*itr)->quest_id;
  11174. if(!(*itr)->db_saved || force_refresh) {
  11175. 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')",
  11176. 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());
  11177. (*itr)->db_saved = true;
  11178. (*itr)->db_index = index;
  11179. if(questID && (*itr)->is_temporary) {
  11180. std::vector<Item*> items;
  11181. GetPlayer()->GetQuestTemporaryRewards(questID, &items);
  11182. if(!force_refresh && items.size() > 0) {
  11183. query.AddQueryAsync(GetCharacterID(), &database, Q_REPLACE, "delete from character_quest_temporary_rewards where char_id = %u and quest_id = %u",
  11184. GetCharacterID(), questID);
  11185. }
  11186. for(int i=0;i<items.size();i++) {
  11187. query.AddQueryAsync(GetCharacterID(), &database, Q_REPLACE, "replace into character_quest_temporary_rewards (char_id, quest_id, item_id, count) values(%u, %u, %u, %u)",
  11188. GetCharacterID(), questID, items[i]->details.item_id, items[i]->details.count);
  11189. }
  11190. }
  11191. }
  11192. index++;
  11193. }
  11194. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  11195. }
  11196. void Client::UpdateCharacterRewardData(QuestRewardData* data) {
  11197. if(!data)
  11198. return;
  11199. if(data->db_saved) {
  11200. Query query;
  11201. 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",
  11202. 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);
  11203. }
  11204. }
  11205. void Client::AddRecipeToPlayerPack(Recipe* recipe, PacketStruct* packet, int16* i) {
  11206. int index = 0;
  11207. if(recipe == nullptr)
  11208. return;
  11209. PlayerRecipeList* prl = GetPlayer()->GetRecipeList();
  11210. if (prl->GetRecipe(recipe->GetID())) {
  11211. delete recipe;
  11212. return;
  11213. }
  11214. auto res = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  11215. if (res != devices.end())
  11216. index = res - devices.begin();
  11217. else
  11218. devices.push_back(recipe->GetDevice());
  11219. prl->AddRecipe(recipe);
  11220. database.SavePlayerRecipe(GetPlayer(), recipe->GetID());
  11221. Message(CHANNEL_NARRATIVE, "Recipe: \"%s\" put in recipe book.", recipe->GetName());
  11222. if (packet && GetRecipeListSent()) {
  11223. packet->setArrayDataByName("id", recipe->GetID(), *i);
  11224. packet->setArrayDataByName("tier", recipe->GetTier(), *i);
  11225. packet->setArrayDataByName("level", recipe->GetLevel(), *i);
  11226. packet->setArrayDataByName("icon", recipe->GetIcon(), *i);
  11227. packet->setArrayDataByName("classes", recipe->GetClasses(), *i);
  11228. //packet->setArrayDataByName("skill", recipe->GetSkill(), *i);
  11229. packet->setArrayDataByName("technique", recipe->GetTechnique(), *i);
  11230. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), *i);
  11231. auto recipe_device = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  11232. if (recipe_device != devices.end())
  11233. packet->setArrayDataByName("device_type", recipe_device - devices.begin(), *i);
  11234. else
  11235. {//TODO error should never get here
  11236. }
  11237. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), *i);
  11238. packet->setArrayDataByName("recipe_name", recipe->GetName(), *i);
  11239. packet->setArrayDataByName("recipe_book", recipe->GetBook(), *i);
  11240. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), *i);
  11241. if(i) {
  11242. (*i)++;
  11243. }
  11244. }
  11245. }
  11246. bool Client::SetPlayerPOVGhost(Spawn* spawn) {
  11247. if(!spawn) {
  11248. pov_ghost_spawn_id = 0;
  11249. SendCharPOVGhost();
  11250. return true;
  11251. }
  11252. int32 ghost_id = player->GetIDWithPlayerSpawn(spawn);
  11253. if(ghost_id) {
  11254. pov_ghost_spawn_id = spawn->GetID();
  11255. SendCharPOVGhost();
  11256. return true;
  11257. }
  11258. return false;
  11259. }
  11260. void Client::HandleDialogSelectMsg(int32 conversation_id, int32 response_index) {
  11261. std::string conversation = "";
  11262. bool conv_established = false;
  11263. MConversation.lock_shared();
  11264. if (conversation_map.count(conversation_id) > 0 && conversation_map[conversation_id].count(response_index) > 0) {
  11265. conversation = std::string(conversation_map[conversation_id][response_index].c_str());
  11266. conv_established = true;
  11267. }
  11268. int32 spawn_id = conversation_spawns[conversation_id];
  11269. Item* item = conversation_items[conversation_id];
  11270. MConversation.unlock_shared();
  11271. if (GetCurrentZone()) {
  11272. Spawn* spawn = nullptr;
  11273. if(spawn_id) {
  11274. spawn = GetCurrentZone()->GetSpawnByID(spawn_id);
  11275. }
  11276. if (conv_established) {
  11277. if (spawn) {
  11278. if(conversation == "CloseItemConversation") {
  11279. LogWrite(LUA__ERROR, 0, "LUA", "CloseItemConversation is an invalid function call for this conversation with spawn id %u", spawn_id);
  11280. }
  11281. else {
  11282. GetCurrentZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_CONVERSATION, player, conversation.c_str());
  11283. }
  11284. }
  11285. else if (item && lua_interface && item->GetItemScript())
  11286. lua_interface->RunItemScript(item->GetItemScript(), conversation.c_str(), item, player);
  11287. else
  11288. CloseDialog(conversation_id);
  11289. }
  11290. else
  11291. CloseDialog(conversation_id);
  11292. }
  11293. }
  11294. bool Client::SetPetName(const char* petName) {
  11295. int8 result = database.CheckNameFilter(petName,4,31);
  11296. if (result == BADNAMELENGTH_REPLY) {
  11297. SimpleMessage(CHANNEL_COLOR_YELLOW, "Name length is invalid, must be greater then 3 characters and less then 31.");
  11298. return false;
  11299. }
  11300. else if (result == NAMEINVALID_REPLY) {
  11301. SimpleMessage(CHANNEL_COLOR_YELLOW, "Name is invalid, can only contain letters.");
  11302. return false;
  11303. }
  11304. else if (result == NAMETAKEN_REPLY) {
  11305. SimpleMessage(CHANNEL_COLOR_YELLOW, "Name is already taken, please choose another.");
  11306. return false;
  11307. }
  11308. else if (result == NAMEFILTER_REPLY) {
  11309. SimpleMessage(CHANNEL_COLOR_YELLOW, "Name failed the filter check.");
  11310. return false;
  11311. }
  11312. else if (result == UNKNOWNERROR_REPLY) {
  11313. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unknown error while checking the name.");
  11314. return false;
  11315. }
  11316. GetPlayer()->GetInfoStruct()->set_pet_name(petName);
  11317. return true;
  11318. }
  11319. bool Client::CheckConsumptionAllowed(int16 slot, bool send_message) {
  11320. switch(slot) {
  11321. case EQ2_FOOD_SLOT: {
  11322. if(GetPlayer()->GetSpellEffectBySpellType(SPELL_TYPE_FOOD)) {
  11323. if(send_message) {
  11324. Message(CHANNEL_NARRATIVE, "If you ate anymore you would explode!");
  11325. }
  11326. return false;
  11327. }
  11328. break;
  11329. }
  11330. case EQ2_DRINK_SLOT: {
  11331. if (GetPlayer()->GetSpellEffectBySpellType(SPELL_TYPE_DRINK))
  11332. {
  11333. if(send_message) {
  11334. Message(CHANNEL_NARRATIVE, "If you drank anymore you would explode!");
  11335. }
  11336. return false;
  11337. }
  11338. break;
  11339. }
  11340. default: {
  11341. if (GetVersion() <= 373) {
  11342. Item* item = GetPlayer()->item_list.GetItemFromIndex(slot);
  11343. if(item->IsFood()) {
  11344. if(item->IsFoodFood()) {
  11345. if(GetPlayer()->GetSpellEffectBySpellType(SPELL_TYPE_FOOD)) {
  11346. if(send_message) {
  11347. Message(CHANNEL_NARRATIVE, "If you ate anymore you would explode!");
  11348. }
  11349. return false;
  11350. }
  11351. return true;
  11352. }
  11353. else if(item->IsFoodDrink()) {
  11354. if (GetPlayer()->GetSpellEffectBySpellType(SPELL_TYPE_DRINK))
  11355. {
  11356. if(send_message) {
  11357. Message(CHANNEL_NARRATIVE, "If you drank anymore you would explode!");
  11358. }
  11359. return false;
  11360. }
  11361. return true;
  11362. }
  11363. }
  11364. }
  11365. return false;
  11366. break;
  11367. }
  11368. }
  11369. return true;
  11370. }
  11371. void Client::StartLinkdeadTimer() {
  11372. if(!linkdead_timer) {
  11373. int32 LD_Timer = rule_manager.GetGlobalRule(R_World, LinkDeadTimer)->GetInt32();
  11374. LogWrite(CCLIENT__DEBUG, 0, "Client", "Starting linkdead timer for %s (timer %u seconds)", GetPlayer()->GetName(), (LD_Timer/1000));
  11375. linkdead_timer = new Timer(LD_Timer);
  11376. linkdead_timer->Enable();
  11377. if(GetPlayer()->GetGroupMemberInfo()) {
  11378. LogWrite(CCLIENT__DEBUG, 0, "Client", "Telling player %s group they are disconnecting", GetPlayer()->GetName());
  11379. world.GetGroupManager()->GroupMessage(GetPlayer()->GetGroupMemberInfo()->group_id, "%s has gone Linkdead.", GetPlayer()->GetName());
  11380. }
  11381. }
  11382. }
  11383. bool Client::IsLinkdeadTimerEnabled() {
  11384. if(linkdead_timer) {
  11385. return linkdead_timer->Enabled();
  11386. }
  11387. return false;
  11388. }
  11389. void Client::SendNewAdventureSpells() {
  11390. SendNewSpells(player->GetAdventureClass());
  11391. int8 base_class = classes.GetBaseClass(player->GetAdventureClass());
  11392. int secondary_class = classes.GetSecondaryBaseClass(player->GetAdventureClass());
  11393. if(base_class != player->GetAdventureClass()) {
  11394. SendNewSpells(base_class);
  11395. }
  11396. if(secondary_class != player->GetAdventureClass() && secondary_class != base_class) {
  11397. SendNewSpells(secondary_class);
  11398. }
  11399. }
  11400. void Client::SendNewTradeskillSpells() {
  11401. SendNewTSSpells(player->GetTradeskillClass());
  11402. int8 secondary_class = classes.GetSecondaryTSBaseClass(player->GetTradeskillClass());
  11403. if(secondary_class != player->GetTradeskillClass()) {
  11404. SendNewTSSpells(secondary_class);
  11405. }
  11406. }
  11407. bool Client::AddRecipeBookToPlayer(int32 recipe_book_id, Item* item) {
  11408. Recipe* master_recipe = master_recipebook_list.GetRecipeBooks(recipe_book_id);
  11409. if(master_recipe) {
  11410. Recipe* recipe_book = new Recipe(master_recipe);
  11411. // if valid recipe book and the player doesn't have it
  11412. if (recipe_book && recipe_book->GetLevel() > GetPlayer()->GetTSLevel()) {
  11413. if(item) {
  11414. Message(CHANNEL_NARRATIVE, "Your tradeskill level is not high enough to scribe this book.");
  11415. }
  11416. safe_delete(recipe_book);
  11417. }
  11418. else if(recipe_book && item && !recipe_book->CanUseRecipeByClass(item, GetPlayer()->GetTradeskillClass())) {
  11419. if(item) {
  11420. Message(CHANNEL_NARRATIVE, "Your tradeskill class cannot use this recipe.");
  11421. }
  11422. safe_delete(recipe_book);
  11423. }
  11424. else if (recipe_book && (!item || !(GetPlayer()->GetRecipeBookList()->HasRecipeBook(recipe_book_id)))){
  11425. LogWrite(PLAYER__DEBUG, 0, "Recipe", "Valid recipe book that the player doesn't have");
  11426. // Add recipe book to the players list
  11427. if(!GetPlayer()->GetRecipeBookList()->HasRecipeBook(recipe_book_id)) {
  11428. GetPlayer()->GetRecipeBookList()->AddRecipeBook(recipe_book);
  11429. }
  11430. std::vector<Recipe*> recipes;
  11431. // Get a list of all recipes this book contains
  11432. if (item && item->recipebook_info) {
  11433. //Backup I guess if the recipe book is empty for whatever reason?
  11434. for (auto& itr : item->recipebook_info->recipes) {
  11435. Recipe* r = master_recipe_list.GetRecipeByCRC(itr); //GetRecipeByName(itr.c_str());
  11436. if (r) {
  11437. recipes.push_back(r);
  11438. }
  11439. }
  11440. LogWrite(PLAYER__DEBUG, 0, "Recipe", "%i recipes found for %s book", recipes.size(), recipe_book->GetBookName());
  11441. }
  11442. else {
  11443. LogWrite(PLAYER__ERROR, 0, "Recipe", "no recipes found for %s book", recipe_book->GetBookName());
  11444. }
  11445. //Filter out duplicate recipes the player already has
  11446. for (auto itr = recipes.begin(); itr != recipes.end();) {
  11447. Recipe* recipe = *itr;
  11448. if (GetPlayer()->GetRecipeList()->GetRecipe(recipe->GetID())) {
  11449. itr = recipes.erase(itr);
  11450. }
  11451. else itr++;
  11452. }
  11453. int16 i = 0;
  11454. // Create the packet to send to update the players recipe list
  11455. PacketStruct* packet = 0;
  11456. if (!recipes.empty() && GetRecipeListSent()) {
  11457. packet = configReader.getStruct("WS_RecipeList", GetVersion());
  11458. if (packet) {
  11459. packet->setArrayLengthByName("num_recipes", recipes.size());
  11460. }
  11461. }
  11462. for (int32 r = 0; r < recipes.size(); r++) {
  11463. Recipe* recipe = recipes[r];
  11464. if (recipe) {
  11465. Recipe* player_recipe = new Recipe(recipe);
  11466. AddRecipeToPlayerPack(player_recipe, packet, &i);
  11467. }
  11468. }
  11469. LogWrite(TRADESKILL__DEBUG, 0, "Recipe", "Done adding recipes");
  11470. database.SavePlayerRecipeBook(GetPlayer(), recipe_book->GetBookID());
  11471. if(item) {
  11472. database.DeleteItem(GetCharacterID(), item, 0);
  11473. GetPlayer()->item_list.RemoveItem(item, true);
  11474. }
  11475. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  11476. SetRecipeListSent(false);
  11477. SendRecipeList();
  11478. safe_delete(packet);
  11479. return true;
  11480. }
  11481. else {
  11482. if (recipe_book && item) {
  11483. Message(CHANNEL_NARRATIVE, "You have already learned all you can from this item.");
  11484. }
  11485. safe_delete(recipe_book);
  11486. }
  11487. }
  11488. else {
  11489. LogWrite(PLAYER__ERROR, 0, "Player", "%u recipe book id does not exist. Cannot AddRecipeToPlayer.", recipe_book_id);
  11490. }
  11491. return false;
  11492. }
  11493. bool Client::RemoveRecipeFromPlayer(int32 recipe_id) {
  11494. PlayerRecipeList* prl = GetPlayer()->GetRecipeList();
  11495. PacketStruct* packet = configReader.getStruct("WS_RecipeList", version);
  11496. Recipe* recipe = prl->GetRecipe(recipe_id);
  11497. int8 level = player->GetTSLevel();
  11498. if(packet && recipe) {
  11499. packet->setDataByName("command_type", 1);
  11500. packet->setArrayLengthByName("num_recipes", 1);
  11501. int32 myid = recipe->GetID();
  11502. int8 rlevel = recipe->GetLevel();
  11503. int8 even = level - level * .05 + .5;
  11504. int8 easymin = level - level * .25 + .5;
  11505. int8 veasymin = level - level * .35 + .5;
  11506. if (rlevel > level )
  11507. packet->setArrayDataByName("tier", 4, 0);
  11508. else if ((rlevel <= level) & (rlevel >= even))
  11509. packet->setArrayDataByName("tier", 3, 0);
  11510. else if ((rlevel <= even) & (rlevel >= easymin))
  11511. packet->setArrayDataByName("tier", 2, 0);
  11512. else if ((rlevel <= easymin) & (rlevel >= veasymin))
  11513. packet->setArrayDataByName("tier", 1, 0);
  11514. else if ((rlevel <= veasymin) & (rlevel >= 0))
  11515. packet->setArrayDataByName("tier", 0, 0);
  11516. if (rlevel == 2)
  11517. int xxx = 1;
  11518. packet->setArrayDataByName("recipe_id", myid, 0);
  11519. packet->setArrayDataByName("level", recipe->GetLevel(), 0);
  11520. packet->setArrayDataByName("unknown1", recipe->GetLevel(), 0);
  11521. packet->setArrayDataByName("icon", recipe->GetIcon(), 0);
  11522. packet->setArrayDataByName("classes", recipe->GetClasses(), 0);
  11523. packet->setArrayDataByName("technique", recipe->GetTechnique(), 0);
  11524. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), 0);
  11525. auto recipe_device = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  11526. if (recipe_device != devices.end())
  11527. packet->setArrayDataByName("device_type", recipe_device - devices.begin(), 0);
  11528. else
  11529. {//TODO error should never get here
  11530. }
  11531. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), 0);
  11532. packet->setArrayDataByName("recipe_name", recipe->GetName(), 0);
  11533. packet->setArrayDataByName("recipe_book", recipe->GetBook(), 0);
  11534. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), 0);
  11535. QueuePacket(packet->serialize());
  11536. }
  11537. safe_delete(packet);
  11538. bool res = prl->RemoveRecipe(recipe_id);
  11539. if(res) {
  11540. Query query;
  11541. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "DELETE FROM character_recipes where char_id=%u and recipe_id=%u", GetCharacterID(), recipe_id);
  11542. }
  11543. return res;
  11544. }
  11545. void Client::SaveSpells() {
  11546. MSaveSpellStateMutex.lock();
  11547. player->SaveSpellEffects();
  11548. player->SetSaveSpellEffects(true);
  11549. MSaveSpellStateMutex.unlock();
  11550. }
  11551. void Client::SendReplaceWidget(int32 widget_id, bool delete_widget, float x, float y, float z, int32 grid_id) {
  11552. Widget* new_spawn = new Widget();
  11553. new_spawn->SetWidgetID(widget_id);
  11554. new_spawn->SetLocation(grid_id);
  11555. new_spawn->SetWidgetX(x);
  11556. new_spawn->SetWidgetY(y);
  11557. new_spawn->SetWidgetZ(z);
  11558. new_spawn->SetX(x);
  11559. new_spawn->SetY(y);
  11560. new_spawn->SetZ(z);
  11561. EQ2Packet* ret = new_spawn->serialize(GetPlayer(), GetVersion());
  11562. QueuePacket(ret);
  11563. // we have to delete spawn* references anyway, we don't keep this widget live in the spawn list
  11564. GetPlayer()->RemoveSpawn(new_spawn, delete_widget);
  11565. safe_delete(new_spawn);
  11566. }
  11567. void Client::ProcessZoneIgnoreWidgets() {
  11568. GetPlayer()->MIgnoredWidgets.lock_shared();
  11569. std::map<int32, bool>::iterator itr;
  11570. for(itr = GetPlayer()->ignored_widgets.begin(); itr != GetPlayer()->ignored_widgets.end(); itr++) {
  11571. SendReplaceWidget(itr->first, true);
  11572. }
  11573. GetPlayer()->MIgnoredWidgets.unlock_shared();
  11574. }
  11575. void Client::PopulateRecipeData(Recipe* recipe, PacketStruct* packet, int i) {
  11576. if(!recipe || !packet)
  11577. return;
  11578. int8 level = player->GetTSLevel();
  11579. int32 myid = recipe->GetID();
  11580. int8 rlevel = recipe->GetLevel();
  11581. int8 even = level - level * .05 + .5;
  11582. int8 easymin = level - level * .25 + .5;
  11583. int8 veasymin = level - level * .35 + .5;
  11584. if (rlevel > level )
  11585. packet->setArrayDataByName("tier", 4, i);
  11586. else if ((rlevel <= level) & (rlevel >= even))
  11587. packet->setArrayDataByName("tier", 3, i);
  11588. else if ((rlevel <= even) & (rlevel >= easymin))
  11589. packet->setArrayDataByName("tier", 2, i);
  11590. else if ((rlevel <= easymin) & (rlevel >= veasymin))
  11591. packet->setArrayDataByName("tier", 1, i);
  11592. else if ((rlevel <= veasymin) & (rlevel >= 0))
  11593. packet->setArrayDataByName("tier", 0, i);
  11594. if (rlevel == 2)
  11595. int xxx = 1;
  11596. packet->setArrayDataByName("recipe_id", myid, i);
  11597. packet->setArrayDataByName("level", recipe->GetLevel(), i);
  11598. packet->setArrayDataByName("icon", recipe->GetIcon(), i);
  11599. packet->setArrayDataByName("classes", recipe->GetClasses(), i);
  11600. packet->setArrayDataByName("technique", recipe->GetTechnique(), i);
  11601. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), i);
  11602. packet->setArrayDataByName("device", recipe->GetDevice(), i);
  11603. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), i);
  11604. packet->setArrayDataByName("recipe_name", recipe->GetName(), i);
  11605. packet->setArrayDataByName("recipe_book", recipe->GetBook(), i);
  11606. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), i);
  11607. packet->setArrayDataByName("book_volume", 0x01, i);
  11608. packet->setArrayDataByName("device_id", 0x01, i);
  11609. }
  11610. int32 Client::GetRecipeCRC(Recipe* recipe) {
  11611. PacketStruct* packet = 0;
  11612. if (!(packet = configReader.getStruct("WS_RecipeDetailList", GetVersion()))) {
  11613. return 0;
  11614. }
  11615. packet->setArrayLengthByName("num_recipes", 1);
  11616. PopulateRecipeData(recipe, packet);
  11617. string* generic_string_data = packet->serializeString();
  11618. int32 size = generic_string_data->length();
  11619. if(size < 5)
  11620. return 0;
  11621. uchar* out_data = new uchar[size+1];
  11622. uchar* out_ptr = out_data;
  11623. memcpy(out_ptr, (uchar*)generic_string_data->c_str()+4, generic_string_data->length()-4);
  11624. uint32 out_crc = GenerateCRCRecipe(0, (void*)out_ptr, size-4);
  11625. safe_delete(packet);
  11626. safe_delete_array(out_data);
  11627. return out_crc;
  11628. }
  11629. void Client::SendRecipeDetails(vector<int32>* recipes) {
  11630. if(!recipes || recipes->size() == 0)
  11631. return;
  11632. PacketStruct* packet = 0;
  11633. if (!(packet = configReader.getStruct("WS_RecipeDetailList", GetVersion()))) {
  11634. return;
  11635. }
  11636. int32 recipe_size = player->GetRecipeList()->Size();
  11637. packet->setArrayLengthByName("num_recipes", recipe_size > 100 ? 100 : recipe_size);
  11638. int16 i = 0;
  11639. int32 count = 0;
  11640. vector<int32>::iterator recipe_itr;
  11641. for(recipe_itr = recipes->begin(); recipe_itr != recipes->end(); recipe_itr++) {
  11642. Recipe* recipe = player->GetRecipeList()->GetRecipe(*recipe_itr);
  11643. if(!recipe) {
  11644. continue;
  11645. }
  11646. else if(i > 99) {
  11647. QueuePacket(packet->serialize());
  11648. safe_delete(packet);
  11649. packet = configReader.getStruct("WS_RecipeDetailList", GetVersion());
  11650. recipe_size -= i;
  11651. packet->setArrayLengthByName("num_recipes", recipe_size > 100 ? 100 : recipe_size);
  11652. i = 0;
  11653. }
  11654. count++;
  11655. PopulateRecipeData(recipe, packet, i);
  11656. i++;
  11657. }
  11658. //packet->PrintPacket();
  11659. QueuePacket(packet->serialize());
  11660. safe_delete(packet);
  11661. }
  11662. ZoneServer* Client::GetHouseZoneServer(int32 spawn_id, int64 house_id) {
  11663. PlayerHouse* ph = nullptr;
  11664. HouseZone* hz = nullptr;
  11665. if(spawn_id) {
  11666. Spawn* houseWidget = GetPlayer()->GetSpawnByIndex(spawn_id);
  11667. if(houseWidget && houseWidget->IsWidget() && ((Widget*)houseWidget)->GetHouseID()) {
  11668. hz = world.GetHouseZone(((Widget*)houseWidget)->GetHouseID());
  11669. if (hz) {
  11670. ph = world.GetPlayerHouseByHouseID(GetPlayer()->GetCharacterID(), hz->id);
  11671. } else {
  11672. Message(CHANNEL_COLOR_YELLOW, "HouseWidget spawn index %u house zone could not be found.", spawn_id);
  11673. }
  11674. }
  11675. }
  11676. if(!ph && house_id) {
  11677. ph = world.GetPlayerHouseByUniqueID(house_id);
  11678. if (ph) {
  11679. hz = world.GetHouseZone(ph->house_id);
  11680. }
  11681. }
  11682. if (ph && hz) {
  11683. ZoneServer* house = zone_list.GetByInstanceID(ph->instance_id, hz->zone_id, false, true);
  11684. return house;
  11685. }
  11686. return nullptr;
  11687. }
  11688. void Client::SendHearCast(Spawn* caster, Spawn* target, int32 spell_visual, int16 cast_time) {
  11689. PacketStruct* packet = configReader.getStruct("WS_HearCastSpell", GetVersion());
  11690. if (packet) {
  11691. int32 caster_id = GetPlayer()->GetIDWithPlayerSpawn(caster);
  11692. int32 target_id = GetPlayer()->GetIDWithPlayerSpawn(target);
  11693. packet->setDataByName("spawn_id", caster_id);
  11694. packet->setArrayLengthByName("num_targets", 1);
  11695. packet->setArrayDataByName("target", target_id);
  11696. packet->setDataByName("num_targets", 1);
  11697. int32 visual = GetSpellVisualOverride(spell_visual);
  11698. packet->setDataByName("spell_visual", visual); //result
  11699. packet->setDataByName("cast_time", cast_time*.01f); //delay
  11700. packet->setDataByName("spell_id", 1);
  11701. packet->setDataByName("spell_level", 1);
  11702. packet->setDataByName("spell_tier", 1);
  11703. EQ2Packet* outapp = packet->serialize();
  11704. DumpPacket(outapp);
  11705. QueuePacket(outapp);
  11706. safe_delete(packet);
  11707. }
  11708. }
  11709. int32 Client::GetSpellVisualOverride(int32 spell_visual) {
  11710. int32 visual = spell_visual;
  11711. if(GetVersion() <= 561) { // spell's spell_visual field is based on newer clients, DoF has to convert
  11712. Emote* spellVisualEmote = visual_states.FindSpellVisualByID(visual, 60085);
  11713. if(spellVisualEmote != nullptr && spellVisualEmote->GetMessageString().size() > 0) {
  11714. spellVisualEmote = visual_states.FindSpellVisual(spellVisualEmote->GetMessageString(), GetVersion());
  11715. if(spellVisualEmote) {
  11716. visual = (int32)spellVisualEmote->GetVisualState();
  11717. }
  11718. }
  11719. }
  11720. return visual;
  11721. }