9
3

client.cpp 485 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408
  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 <boost/property_tree/json_parser.hpp>
  28. #include "Player.h"
  29. #include "PlayerGroups.h"
  30. #include "Commands/Commands.h"
  31. #include "ClientPacketFunctions.h"
  32. #include "../common/ConfigReader.h"
  33. #include "Guilds/Guild.h"
  34. #include "Variables.h"
  35. #include "Rules/Rules.h"
  36. #include "Titles.h"
  37. #include "Chat/Chat.h"
  38. #include "SpellProcess.h"
  39. #include "Zone/ChestTrap.h"
  40. #include "../common/GlobalHeaders.h"
  41. #include "./Web/PeerManager.h"
  42. #include "./Web/HTTPSClientPool.h"
  43. //#include "Quests.h"
  44. #ifdef WIN32
  45. #include <WinSock2.h>
  46. #include <windows.h>
  47. #define snprintf _snprintf
  48. #define vsnprintf _vsnprintf
  49. #define strncasecmp _strnicmp
  50. #define strcasecmp _stricmp
  51. #else
  52. #include <sys/socket.h>
  53. #ifdef FREEBSD
  54. #include <sys/types.h>
  55. #endif
  56. #include <netinet/in.h>
  57. #include <arpa/inet.h>
  58. #include <unistd.h>
  59. #endif
  60. #if defined(__GNUC__)
  61. #define _snprintf snprintf
  62. #endif
  63. #include "client.h"
  64. #include "../common/emu_opcodes.h"
  65. #include "../common/packet_dump.h"
  66. #include "WorldDatabase.h"
  67. #include "races.h"
  68. #include "classes.h"
  69. #include "LoginServer.h"
  70. #include "World.h"
  71. #include "../common/EQ2_Common_Structs.h"
  72. #include "net.h"
  73. #include "../common/MiscFunctions.h"
  74. #include "Skills.h"
  75. #include "LuaInterface.h"
  76. #include "Quests.h"
  77. #include "Collections/Collections.h"
  78. #include "Achievements/Achievements.h"
  79. #include "Traits/Traits.h"
  80. #include "Recipes/Recipe.h"
  81. #include "Tradeskills/Tradeskills.h"
  82. #include "AltAdvancement/AltAdvancement.h"
  83. #include "Bots/Bot.h"
  84. #include "VisualStates.h"
  85. extern WorldDatabase database;
  86. extern const char* ZONE_NAME;
  87. extern LoginServer loginserver;
  88. extern sint32 numclients;
  89. extern NetConnection net;
  90. extern Commands commands;
  91. extern ClientList client_list;
  92. extern ZoneList zone_list;
  93. extern ZoneAuth zone_auth;
  94. extern MasterItemList master_item_list;
  95. extern MasterSkillList master_skill_list;
  96. extern MasterSpellList master_spell_list;
  97. extern MasterTraitList master_trait_list;
  98. extern MasterQuestList master_quest_list;
  99. extern MasterFactionList master_faction_list;
  100. extern MasterRecipeList master_recipe_list;
  101. extern volatile bool RunLoops;
  102. extern ConfigReader configReader;
  103. extern LuaInterface* lua_interface;
  104. extern World world;
  105. extern Variables variables;
  106. extern Classes classes;
  107. extern Races races;
  108. extern GuildList guild_list;
  109. extern MasterCollectionList master_collection_list;
  110. extern MasterAchievementList master_achievement_list;
  111. extern RuleManager rule_manager;
  112. extern Chat chat;
  113. extern MasterAAList master_aa_list;
  114. extern MasterAAList master_tree_nodes;
  115. extern ChestTrapList chest_trap_list;
  116. extern MasterRecipeBookList master_recipebook_list;
  117. extern VisualStates visual_states;
  118. extern PeerManager peer_manager;
  119. extern HTTPSClientPool peer_https_pool;
  120. using namespace std;
  121. 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) {
  122. eqs = ieqs;
  123. ip = eqs->GetrIP();
  124. port = ntohs(eqs->GetrPort());
  125. merchant_transaction = nullptr;
  126. mail_window.item = nullptr; // don't want this to be set(loose ptr) when using ResetSendMail to provide rest of the defaults
  127. ResetSendMail(false);
  128. timestamp_flag = 0;
  129. current_quest_id = 0;
  130. last_update_time = 0;
  131. quest_updates = false;
  132. //autobootup_timeout = new Timer(10000);
  133. //autobootup_timeout->Disable();
  134. CLE_keepalive_timer = new Timer(15000);
  135. connect = new Timer(1000);
  136. connect->Disable();
  137. zoneID = 0;
  138. account_name[0] = 0;
  139. character_id = 0;
  140. account_id = 0;
  141. pwaitingforbootup = 0;
  142. current_zone = 0;
  143. connected_to_zone = false;
  144. connected = false;
  145. camp_timer = 0;
  146. linkdead_timer = 0;
  147. client_zoning = false;
  148. client_zoning_details_set = false;
  149. zoning_id = 0;
  150. zoning_x = 0;
  151. zoning_y = 0;
  152. zoning_z = 0;
  153. zoning_instance_id = 0;
  154. player_pos_changed = false;
  155. player_pos_timer = Timer::GetCurrentTime2() + 1000;
  156. enabled_player_pos_timer = true;
  157. ++numclients;
  158. if (world.GetServerStatisticValue(STAT_SERVER_MOST_CONNECTIONS) < numclients)
  159. world.UpdateServerStatistic(STAT_SERVER_MOST_CONNECTIONS, numclients, true);
  160. remove_from_list = false;
  161. new_client_login = NewLoginState::LOGIN_NONE;
  162. UpdateWindowTitle(0);
  163. num_active_failures = 0;
  164. player = new Player();
  165. player->SetClient(this);
  166. combine_spawn = 0;
  167. lua_debug = false;
  168. ready_for_spawns = false;
  169. ready_for_updates = false;
  170. lua_debug_timer.Disable();
  171. transport_spawn = 0;
  172. MBuyBack.SetName("Client::MBuyBack");
  173. MDeletePlayer.SetName("Client::MDeletePlayer");
  174. MQuestPendingUpdates.SetName("Client::MQuestPendingUpdates");
  175. search_items = 0;
  176. version = 0;
  177. next_conversation_id = 0;
  178. pending_guild_invite.guild = 0;
  179. pending_guild_invite.invited_by = 0;
  180. m_recipeListSent = false;
  181. m_resurrect.SetName("Client::m_resurrect");
  182. current_rez.expire_timer = 0;
  183. current_rez.should_delete = true;
  184. pending_last_name = 0;
  185. should_target = false;
  186. initial_spawns_sent = false;
  187. MQuestTimers.SetName("Client::quest_timers");
  188. memset(&incoming_paperdoll, 0, sizeof(incoming_paperdoll));
  189. on_auto_mount = false;
  190. should_load_spells = true;
  191. spawnPlacementMode = ServerSpawnPlacementMode::DEFAULT;
  192. delayedLogin = false;
  193. delayedAccountID = 0;
  194. delayedAccessKey = 0;
  195. delayTimer.Disable();
  196. tempPlacementSpawn = nullptr;
  197. placement_unique_item_id = 0;
  198. SetHasOwnerOrEditAccess(false);
  199. temporary_transport_id = 0;
  200. rejoin_group_id = 0;
  201. lastRegionRemapTime = 0;
  202. regionDebugMessaging = false;
  203. client_reloading_zone = false;
  204. last_saved_timestamp = 0;
  205. MQueueStateCmds.SetName("Client::MQueueStateCmds");
  206. save_spell_state_timer.Disable();
  207. save_spell_state_time_bucket = 0;
  208. player_loading_complete = false;
  209. MItemDetails.SetName("Client::MItemDetails");
  210. MSpellDetails.SetName("Client::MSpellDetails");
  211. hasSentTempPlacementSpawn = false;
  212. spawn_removal_timer.Start();
  213. disable_save = false;
  214. SetZoningDestination(nullptr);
  215. underworld_cooldown_timer.Disable();
  216. player_pos_change_count = 0;
  217. pov_ghost_spawn_id = 0;
  218. recipe_orig_packet = nullptr;
  219. recipe_xor_packet = nullptr;
  220. recipe_packet_count = 0;
  221. recipe_orig_packet_size = 0;
  222. }
  223. Client::~Client() {
  224. RemoveClientFromZone();
  225. //let the stream factory know were done with this stream
  226. if (eqs) {
  227. eqs->Close();
  228. try {
  229. eqs->ReleaseFromUse();
  230. }
  231. catch (...) {}
  232. }
  233. eqs = NULL;
  234. //safe_delete(autobootup_timeout);
  235. safe_delete(linkdead_timer);
  236. vector<QueuedQuest*>::iterator itr;
  237. QueuedQuest* queued_quest = 0;
  238. for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
  239. queued_quest = *itr;
  240. safe_delete(queued_quest);
  241. }
  242. quest_queue.clear();
  243. vector<QuestRewardData*>::iterator rwd_itr;
  244. QuestRewardData* quest_rwd_data = 0;
  245. for (rwd_itr = quest_pending_reward.begin(); rwd_itr != quest_pending_reward.end(); rwd_itr++) {
  246. quest_rwd_data = *rwd_itr;
  247. safe_delete(quest_rwd_data);
  248. }
  249. quest_pending_reward.clear();
  250. safe_delete(CLE_keepalive_timer);
  251. safe_delete(connect);
  252. --numclients;
  253. UpdateWindowTitle(0);
  254. }
  255. void Client::RemoveClientFromZone() {
  256. if (player && player->GetZone())
  257. player->GetZone()->GetSpellProcess()->RemoveSpellTimersFromSpawn(player, true, false, true, true);
  258. if (GetTempPlacementSpawn() && GetCurrentZone()) {
  259. Spawn* tmp = GetTempPlacementSpawn();
  260. SetTempPlacementSpawn(nullptr);
  261. GetCurrentZone()->RemoveSpawn(tmp, true, false, true, true, true);
  262. }
  263. if (current_zone && player) {
  264. if (player->GetGroupMemberInfo()) {
  265. TempRemoveGroup();
  266. }
  267. world.GetGroupManager()->ClearPendingInvite(player);
  268. }
  269. if (lua_interface)
  270. lua_interface->RemoveDebugClients(this);
  271. if (player)
  272. zone_list.RemoveClientFromMap(player->GetName(), this);
  273. safe_delete(camp_timer);
  274. safe_delete(search_items);
  275. safe_delete(current_rez.expire_timer);
  276. safe_delete(pending_last_name);
  277. safe_delete_array(incoming_paperdoll.image_bytes);
  278. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  279. player = nullptr;
  280. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  281. deque<BuyBackItem*>::iterator itr;
  282. MBuyBack.writelock(__FUNCTION__, __LINE__);
  283. for (itr = buy_back_items.begin(); itr != buy_back_items.end();) {
  284. safe_delete(*itr);
  285. itr = buy_back_items.erase(itr);
  286. }
  287. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  288. }
  289. void Client::QueuePacket(EQ2Packet* app, bool attemptedCombine) {
  290. if (eqs) {
  291. if (!eqs->CheckActive()) {
  292. client_list.Remove(this);
  293. eqs = 0;
  294. }
  295. }
  296. if (app && eqs && version > 0)
  297. eqs->EQ2QueuePacket(app, attemptedCombine);
  298. else {
  299. safe_delete(app);
  300. }
  301. }
  302. void Client::PopulateSkillMap() {
  303. EQ2Packet* app = master_skill_list.GetPopulateSkillsPacket(GetVersion());
  304. if (app)
  305. QueuePacket(app);
  306. else {
  307. LogWrite(WORLD__ERROR, 0, "World", "Unable to send populate skills packet for version: %i!", GetVersion());
  308. Disconnect(); //the client cant proceed without the skill packet, might as well kick it now
  309. }
  310. }
  311. void Client::SendLoginInfo() {
  312. if (GetPlayer()->IsReturningFromLD())
  313. firstlogin = true;
  314. if (firstlogin) {
  315. LogWrite(WORLD__DEBUG, 0, "World", "Increment Server_Accepted_Connection + 1");
  316. world.UpdateServerStatistic(STAT_SERVER_ACCEPTED_CONNECTION, 1);
  317. LogWrite(CCLIENT__DEBUG, 0, "Client", "Populate Skill Map...");
  318. PopulateSkillMap();
  319. // 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!
  320. LogWrite(MISC__TODO, 1, "TODO", "Check client version at login, move char if invalid zone file");
  321. }
  322. LogWrite(CCLIENT__DEBUG, 0, "Client", "Toggle Character Online...");
  323. database.ToggleCharacterOnline(this, 1);
  324. int32 count = 0;
  325. if (!GetPlayer()->IsReturningFromLD())
  326. {
  327. count = database.LoadCharacterTitles(GetCharacterID(), player);
  328. if (count == 0) {
  329. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character titles found!");
  330. LogWrite(CCLIENT__DEBUG, 0, "Client", "Initializing starting values - Titles");
  331. database.UpdateStartingTitles(GetCharacterID(), player->GetAdventureClass(), player->GetRace(), player->GetGender());
  332. }
  333. }
  334. if (!GetPlayer()->IsReturningFromLD())
  335. {
  336. count = database.LoadCharacterLanguages(GetCharacterID(), player);
  337. if (count == 0)
  338. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character languages loaded!");
  339. count = database.LoadPlayerRecipeBooks(GetCharacterID(), player);
  340. if (count == 0)
  341. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character recipe books found!");
  342. }
  343. ClientPacketFunctions::SendLoginAccepted(this);
  344. ClientPacketFunctions::SendAbilities(this);
  345. ClientPacketFunctions::SendCommandNamePacket(this);
  346. ClientPacketFunctions::SendQuickBarInit(this);
  347. // we only need to send the MOTD if it is the first time the person is logging in.
  348. if (firstlogin) {
  349. ClientPacketFunctions::SendMOTD(this);
  350. ClientPacketFunctions::SendCharacterMacros(this);
  351. zone_list.CheckFriendList(this);
  352. }
  353. if (!GetPlayer()->IsReturningFromLD())
  354. {
  355. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  356. if (firstlogin && player->item_list.GetNumberOfItems() == 0 && player->GetEquipmentList()->GetNumberOfItems() == 0) //re-add starting items if missing
  357. {
  358. LogWrite(CCLIENT__WARNING, 0, "Client", "Player has no items - reloading starting items: '%s' (%u)", player->GetName(), GetCharacterID());
  359. database.UpdateStartingItems(GetCharacterID(), player->GetAdventureClass(), player->GetRace());
  360. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  361. }
  362. GetPlayer()->item_list.SetMaxItemIndex();
  363. database.LoadPlayerFactions(this);
  364. database.LoadCharacterQuests(this);
  365. database.LoadCharacterQuestRewards(this);
  366. database.LoadPlayerMail(this);
  367. }
  368. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  369. SendQuestJournal(true, 0, false);
  370. if (version > 561) // right version? possibly not!
  371. master_aa_list.DisplayAA(this, 0, 3);
  372. if (version > 373)
  373. SendCollectionList();
  374. SendBiography();
  375. map<int32, Quest*>::iterator itr;
  376. Quest* quest = 0;
  377. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  378. for (itr = player->player_quests.begin(); itr != player->player_quests.end(); itr++) {
  379. quest = itr->second;
  380. if (quest->IsTracked()) {
  381. quest->SetTracked(false);
  382. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  383. quest->SetTracked(true);
  384. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  385. }
  386. }
  387. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  388. // SendAchievementsList();
  389. /*Guild* guild = player->GetGuild();
  390. if (guild) {
  391. guild->UpdateGuildMemberInfo(GetPlayer());
  392. if (firstlogin)
  393. guild->SendGuildMOTD(this);
  394. guild->SendGuildUpdate(this);
  395. guild->SendGuildMember(GetPlayer(), firstlogin);
  396. guild->SendGuildEventList(this);
  397. guild->SendGuildBankEventList(this);
  398. guild->SendAllGuildEvents(this);
  399. guild->SendGuildMemberList(this);
  400. }*/
  401. if (version > 373) {
  402. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Faction Updates...");
  403. EQ2Packet* outapp = player->GetFactions()->FactionUpdate(GetVersion());
  404. if (outapp) {
  405. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  406. //DumpPacket(outapp);
  407. QueuePacket(outapp);
  408. }
  409. }
  410. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Command List...");
  411. ClientPacketFunctions::SendCommandList(this);
  412. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Language Updates...");
  413. // kos doesn't like one of these language or instance list
  414. SendLanguagesUpdate(database.GetCharacterCurrentLang(GetCharacterID(), player));
  415. //ClientPacketFunctions::SendInstanceList(this);
  416. SendZoneInfo();
  417. /*Spell* spell = 0;
  418. vector<QuickBarItem*>::iterator itr;
  419. for(itr = player->GetQuickbar()->begin(); itr != player->GetQuickbar()->end(); itr++){
  420. if((*itr)->type == 1){
  421. spell = master_spell_list.GetSpell((*itr)->id);
  422. if(spell)
  423. QueuePacket(spell->serialize(this, false, 0x20));
  424. }
  425. }*/
  426. }
  427. void Client::SendPlayerDeathWindow()
  428. {
  429. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendPlayerDeathWindow");
  430. vector<RevivePoint*>* results = GetCurrentZone()->GetRevivePoints(this);
  431. vector<RevivePoint*>::iterator itr;
  432. if (results && results->size() > 0)
  433. {
  434. PacketStruct* packet = configReader.getStruct("WS_DeathWindow", GetVersion());
  435. if (packet)
  436. {
  437. packet->setArrayLengthByName("location_count", results->size());
  438. RevivePoint* point = 0;
  439. int32 i = 0;
  440. for (itr = results->begin(); itr != results->end(); itr++, i++)
  441. {
  442. point = *itr;
  443. if (point)
  444. {
  445. packet->setArrayDataByName("location_id", point->id, i);
  446. //zone_name = database.GetZoneName(point->zone_id);
  447. string zone_name = database.GetZoneDescription(point->zone_id);
  448. if (zone_name.length() > 0)
  449. packet->setArrayDataByName("zone_name", zone_name.c_str(), i);
  450. packet->setArrayDataByName("location_name", point->location_name.c_str(), i);
  451. packet->setArrayDataByName("distance", GetPlayer()->GetDistance(point->x, point->y, point->z), i);
  452. }
  453. if (point->id == 0xFFFFFFFF)//tmp location
  454. safe_delete(point);
  455. }
  456. #if EQDEBUG >= 3
  457. LogWrite(CCLIENT__DEBUG, 0, "Client", "WS_DeathWindow Packet:");
  458. packet->PrintPacket();
  459. #endif
  460. EQ2Packet* outapp = packet->serialize();
  461. QueuePacket(outapp);
  462. safe_delete(packet);
  463. }
  464. // done with the revive points so lets free up the pointer
  465. safe_delete(results);
  466. }
  467. }
  468. void Client::DisplayDeadWindow()
  469. {
  470. LogWrite(ZONE__DEBUG, 0, "Zone", "DisplayDeadWindow()");
  471. player->SetHP(0);
  472. player->SetPower(0);
  473. GetCurrentZone()->TriggerCharSheetTimer();
  474. if (GetVersion() <= 561) {
  475. ClientPacketFunctions::SendServerControlFlagsClassic(this, 8, 1);
  476. ClientPacketFunctions::SendServerControlFlagsClassic(this, 16, 1);
  477. }
  478. else {
  479. ClientPacketFunctions::SendServerControlFlags(this, 1, 8, 1);
  480. ClientPacketFunctions::SendServerControlFlags(this, 1, 16, 1);
  481. }
  482. PacketStruct* packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  483. if (packet)
  484. {
  485. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  486. QueuePacket(packet->serialize());
  487. safe_delete(packet);
  488. }
  489. SendPlayerDeathWindow();
  490. }
  491. void Client::HandlePlayerRevive(int32 point_id)
  492. {
  493. if (GetVersion() <= 561) {
  494. ClientPacketFunctions::SendServerControlFlagsClassic(this, 8, 0);
  495. ClientPacketFunctions::SendServerControlFlagsClassic(this, 16, 0);
  496. }
  497. else {
  498. ClientPacketFunctions::SendServerControlFlags(this, 1, 8, 0);
  499. ClientPacketFunctions::SendServerControlFlags(this, 1, 16, 0);
  500. }
  501. SimpleMessage(CHANNEL_NARRATIVE, "You regain consciousness!");
  502. PacketStruct* packet = configReader.getStruct("WS_Resurrected", GetVersion());
  503. if (packet)
  504. {
  505. QueuePacket(packet->serialize());
  506. safe_delete(packet);
  507. }
  508. float origX, origY, origZ, origHeading = 0.0f;
  509. origX = player->GetX();
  510. origY = player->GetY();
  511. origZ = player->GetZ();
  512. origHeading = player->GetHeading();
  513. ZoneServer* originalZone = GetCurrentZone();
  514. int32 origGridID = GetPlayer()->GetLocation();
  515. float x, y, z, heading;
  516. RevivePoint* revive_point = 0;
  517. if (point_id != 0xFFFFFFFF)
  518. revive_point = GetCurrentZone()->GetRevivePoint(point_id);
  519. string zone_desc;
  520. const char* location_name = "Unknown";
  521. player->SetAlive(true);
  522. player->SetResurrecting(true);
  523. player->SetHP(player->GetTotalHP());
  524. player->SetPower(player->GetTotalPower());
  525. //revive at zone safe coords
  526. if (!revive_point)
  527. {
  528. LogWrite(CCLIENT__WARNING, 0, "Client", "No Revive Point! Spawning player at safe coordinates!");
  529. x = GetCurrentZone()->GetSafeX();
  530. y = GetCurrentZone()->GetSafeY();
  531. z = GetCurrentZone()->GetSafeZ();
  532. heading = GetCurrentZone()->GetSafeHeading();
  533. zone_desc = GetCurrentZone()->GetZoneDescription();
  534. location_name = "Zone Safe Point";
  535. Zone(GetCurrentZone()->GetZoneName(), false);
  536. }
  537. else
  538. {
  539. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to chosen Revive Point.");
  540. x = revive_point->x;
  541. y = revive_point->y;
  542. z = revive_point->z;
  543. heading = revive_point->heading;
  544. zone_desc = database.GetZoneDescription(revive_point->zone_id);
  545. location_name = revive_point->location_name.c_str();
  546. Zone(GetCurrentZone()->GetZoneName(), false);
  547. }
  548. player->SetX(x);
  549. player->SetY(y);
  550. player->SetZ(z);
  551. player->SetHeading(heading);
  552. LogWrite(CCLIENT__DEBUG, 0, "Client", "Attempt Revive @ %s, %.2f, %.2f, %.2f, %.2f, HP: %i, Pow: %i, %s",
  553. zone_desc.c_str(),
  554. player->GetX(),
  555. player->GetY(),
  556. player->GetZ(),
  557. player->GetHeading(),
  558. player->GetHP(),
  559. player->GetPower(),
  560. location_name);
  561. //player->ClearEverything();
  562. Save();
  563. if (revive_point && revive_point->zone_id != GetCurrentZone()->GetZoneID() && revive_point->zone_id != 0)
  564. {
  565. string zone_name = database.GetZoneName(revive_point->zone_id);
  566. if (zone_name.length() == 0)
  567. {
  568. LogWrite(CCLIENT__WARNING, 0, "Client", "Unable to zone player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  569. x = GetCurrentZone()->GetSafeX();
  570. y = GetCurrentZone()->GetSafeY();
  571. z = GetCurrentZone()->GetSafeZ();
  572. heading = GetCurrentZone()->GetSafeHeading();
  573. location_name = "Zone Safe Point";
  574. }
  575. else
  576. {
  577. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  578. location_name = revive_point->location_name.c_str();
  579. //player->ClearEverything();
  580. Save();
  581. Zone(zone_name.c_str(), false);
  582. }
  583. }
  584. zone_desc = GetCurrentZone()->GetZoneDescription();
  585. Message(CHANNEL_NARRATIVE, "Reviving in %s at %s.", zone_desc.c_str(), location_name);
  586. player->SetSpawnType(4);
  587. if (version > 373) {
  588. packet = configReader.getStruct("WS_CancelMoveObjectMode", GetVersion());
  589. if (packet)
  590. {
  591. QueuePacket(packet->serialize());
  592. safe_delete(packet);
  593. }
  594. }
  595. packet = configReader.getStruct("WS_TeleportWithinZone", GetVersion());
  596. if (packet)
  597. {
  598. packet->setDataByName("x", x);
  599. packet->setDataByName("y", y);
  600. packet->setDataByName("z", z);
  601. QueuePacket(packet->serialize());
  602. safe_delete(packet);
  603. }
  604. SendControlGhost();
  605. packet = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  606. if (packet)
  607. {
  608. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  609. QueuePacket(packet->serialize());
  610. safe_delete(packet);
  611. }
  612. if (rule_manager.GetZoneRule(GetCurrentZoneID(), R_Combat, EnableSpiritShards)->GetBool())
  613. {
  614. NPC* shard = player->InstantiateSpiritShard(origX, origY, origZ, origHeading, origGridID, originalZone);
  615. if (shard->GetSpawnScript() && strlen(shard->GetSpawnScript()) > 0)
  616. originalZone->CallSpawnScript(shard, SPAWN_SCRIPT_PRESPAWN);
  617. originalZone->RemoveSpawn(player, false, true, true, true, true);
  618. originalZone->AddSpawn(shard);
  619. if (shard->GetSpawnScript() && strlen(shard->GetSpawnScript()) > 0)
  620. originalZone->CallSpawnScript(shard, SPAWN_SCRIPT_SPAWN);
  621. }
  622. m_resurrect.writelock(__FUNCTION__, __LINE__);
  623. if (current_rez.active)
  624. current_rez.should_delete = true;
  625. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  626. }
  627. void Client::SendControlGhost(int32 send_id, int8 unknown2) {
  628. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", GetVersion());
  629. if (packet) {
  630. packet->setDataByName("spawn_id", send_id);
  631. packet->setDataByName("speed", GetPlayer()->GetSpeed());
  632. packet->setDataByName("size", 0.51);
  633. packet->setDataByName("unknown2", unknown2);
  634. packet->setDataByName("air_speed", player->GetAirSpeed());
  635. EQ2Packet* app = packet->serialize();
  636. QueuePacket(app);
  637. safe_delete(packet);
  638. }
  639. }
  640. void Client::SendCharInfo() {
  641. EQ2Packet* app;
  642. player->SetEquippedItemAppearances();
  643. ClientPacketFunctions::SendCharacterData(this);
  644. SendCharPOVGhost();
  645. SendControlGhost(player->GetIDWithPlayerSpawn(player), 255);
  646. //sending bad spawn packet?
  647. //SendAchievementsList();
  648. //if (version > 561)
  649. //ClientPacketFunctions::SendHousingList(this);
  650. ClientPacketFunctions::SendCharacterSheet(this);
  651. ClientPacketFunctions::SendTraitList(this);// moved from below
  652. ClientPacketFunctions::SendAbilities(this);
  653. ClientPacketFunctions::SendSkillBook(this);
  654. if (!IsReloadingZone() && !player->IsResurrecting() && GetVersion() >= 546) {
  655. ClientPacketFunctions::SendUpdateSpellBook(this);
  656. }
  657. else {
  658. player->SetResurrecting(false);
  659. }
  660. GetCurrentZone()->AddSpawn(player);
  661. if (IsReloadingZone() && (zoning_x || zoning_y || zoning_z)) {
  662. GetPlayer()->SetX(zoning_x);
  663. GetPlayer()->SetY(zoning_y);
  664. GetPlayer()->SetZ(zoning_z);
  665. GetPlayer()->SetHeading(zoning_h);
  666. EQ2Packet* packet = GetPlayer()->Move(zoning_x, zoning_y, zoning_z, GetVersion(), zoning_h);
  667. QueuePacket(packet);
  668. }
  669. //SendCollectionList();
  670. Guild* guild = player->GetGuild();
  671. if (guild)
  672. guild->GuildMemberLogin(this, firstlogin);
  673. app = player->GetPlayerItemList()->serialize(GetPlayer(), GetVersion());
  674. if (app) {
  675. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  676. //DumpPacket(app);
  677. QueuePacket(app);
  678. }
  679. app = player->GetEquipmentList()->serialize(GetVersion(), player);
  680. if (app) {
  681. QueuePacket(app);
  682. }
  683. app = player->GetAppearanceEquipmentList()->serialize(GetVersion(), player);
  684. if (app) {
  685. QueuePacket(app);
  686. }
  687. vector<Item*>* items = player->GetPlayerItemList()->GetItemsFromBagID(-3); // bank items
  688. if (items && items->size() > 0) {
  689. for (int32 i = 0; i < items->size(); i++) {
  690. EQ2Packet* outapp = items->at(i)->serialize(GetVersion(), false, GetPlayer());
  691. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  692. //DumpPacket(outapp);
  693. QueuePacket(outapp);
  694. }
  695. }
  696. if (firstlogin && (app = chat.GetWorldChannelList(this)) != NULL)
  697. QueuePacket(app);
  698. safe_delete(items);
  699. items = player->GetPlayerItemList()->GetItemsFromBagID(-4); //shared bank items
  700. if (items && items->size() > 0) {
  701. for (int32 i = 0; i < items->size(); i++)
  702. QueuePacket(items->at(i)->serialize(GetVersion(), false, GetPlayer()));
  703. }
  704. safe_delete(items);
  705. if (version >= 373) {
  706. SendTitleUpdate();
  707. }
  708. GetPlayer()->UpdateWeapons();
  709. if (!GetPlayer()->IsReturningFromLD()) {
  710. database.LoadBuyBacks(this);
  711. }
  712. if (version > 561)
  713. master_aa_list.DisplayAA(this, 0, 0);
  714. string zone_motd = GetCurrentZone()->GetZoneMOTD();
  715. if (zone_motd.length() > 0 && zone_motd[0] != ' ') {
  716. string zone_motd_send = "Zone MOTD: " + zone_motd;
  717. SimpleMessage(CHANNEL_NARRATIVE, zone_motd_send.c_str());
  718. }
  719. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  720. if (zone_script && lua_interface)
  721. lua_interface->RunZoneScript(zone_script, "player_entry", GetCurrentZone(), GetPlayer());
  722. this->client_zoning = false;
  723. this->client_zoning_details_set = false;
  724. this->zoning_id = 0;
  725. this->zoning_instance_id = 0;
  726. SetZoningDestination(nullptr);
  727. if (player->GetHP() < player->GetTotalHP() || player->GetPower() < player->GetTotalPower())
  728. GetCurrentZone()->AddDamagedSpawn(player);
  729. if (firstlogin)
  730. firstlogin = false;
  731. player->ClearProcs();
  732. items = player->GetEquippedItemList();
  733. if (items && items->size() > 0) {
  734. for (int32 i = 0; i < items->size(); i++) {
  735. Item* item = items->at(i);
  736. if (item && item->GetItemScript() && lua_interface)
  737. lua_interface->RunItemScript(item->GetItemScript(), "equipped", item, player);
  738. }
  739. }
  740. //Allow this player to change their last name if they meet the level requirement
  741. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && player->GetLevel() >= rule_manager.GetZoneRule(GetCurrentZoneID(), R_Player, MinLastNameLevel)->GetInt8())
  742. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  743. safe_delete(items);
  744. if (!player->Alive())
  745. DisplayDeadWindow();
  746. ClientPacketFunctions::SendLocalizedTextMessage(this);
  747. if (GetCurrentZone()->GetInstanceID())
  748. {
  749. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(GetCurrentZone()->GetInstanceID());
  750. if (ph) {
  751. //HouseZone* hz = world.GetHouseZone(ph->house_id);
  752. string name = string(GetPlayer()->GetName());
  753. if (name.compare(ph->player_name) == 0)
  754. SetHasOwnerOrEditAccess(true);
  755. }
  756. }
  757. bool groupMentor = false;
  758. GetPlayer()->group_id = rejoin_group_id;
  759. if (!world.RejoinGroup(this, rejoin_group_id))
  760. GetPlayer()->group_id = 0;
  761. else
  762. {
  763. Entity* ent = world.GetGroupManager()->IsPlayerInGroup(rejoin_group_id, GetPlayer()->GetGroupMemberInfo()->mentor_target_char_id);
  764. if (ent && ent->IsPlayer())
  765. {
  766. GetPlayer()->SetMentorStats(ent->GetLevel(), ent->GetID(), false);
  767. groupMentor = true;
  768. }
  769. }
  770. if (!groupMentor)
  771. GetPlayer()->SetMentorStats(GetPlayer()->GetLevel(), 0, false);
  772. if (!GetPlayer()->IsReturningFromLD()) {
  773. database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_MAINTAINEDEFFECTS);
  774. database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_SPELLEFFECTS);
  775. }
  776. else {
  777. Spawn* pet_spawn = nullptr;
  778. if (GetPlayer()->GetPet())
  779. pet_spawn = GetPlayer()->GetPet();
  780. else if (GetPlayer()->GetCharmedPet())
  781. pet_spawn = GetPlayer()->GetCharmedPet();
  782. else if (GetPlayer()->GetCosmeticPet())
  783. pet_spawn = GetPlayer()->GetCosmeticPet();
  784. else if (GetPlayer()->GetDeityPet())
  785. pet_spawn = GetPlayer()->GetDeityPet();
  786. if (pet_spawn) {
  787. GetPlayer()->GetInfoStruct()->set_pet_id(GetPlayer()->GetIDWithPlayerSpawn(pet_spawn));
  788. }
  789. }
  790. GetPlayer()->SetSaveSpellEffects(false);
  791. GetPlayer()->SetCharSheetChanged(true);
  792. GetPlayer()->SetReturningFromLD(false);
  793. }
  794. void Client::SendZoneSpawns() {
  795. //Allows us to place spawns almost anywhere
  796. if (version > 373) {
  797. uchar blah[] = { 0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46 };
  798. EQ2Packet* app = new EQ2Packet(OP_MoveableObjectPlacementCriteri, blah, sizeof(blah));
  799. QueuePacket(app);
  800. }
  801. ClientPacketFunctions::SendSkillSlotMappings(this);
  802. ClientPacketFunctions::SendGameWorldTime(this);
  803. GetCurrentZone()->StartZoneInitialSpawnThread(this);
  804. }
  805. void Client::SendCharPOVGhost() {
  806. bool use_ghost_pov = false;
  807. PacketStruct* set_pov = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  808. int32 ghost_id = 0;
  809. if (set_pov) {
  810. if (pov_ghost_spawn_id) {
  811. Spawn* spawn = GetCurrentZone()->GetSpawnByID(pov_ghost_spawn_id);
  812. ghost_id = player->GetIDWithPlayerSpawn(spawn);
  813. if (spawn) {
  814. use_ghost_pov = true;
  815. }
  816. }
  817. if (use_ghost_pov) {
  818. set_pov->setDataByName("spawn_id", ghost_id);
  819. }
  820. else {
  821. set_pov->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  822. }
  823. EQ2Packet* app_pov = set_pov->serialize();
  824. QueuePacket(app_pov);
  825. safe_delete(set_pov);
  826. }
  827. }
  828. void Client::SendZoneInfo() {
  829. ZoneServer* zone = GetCurrentZone();
  830. if (zone) {
  831. EQ2Packet* packet = zone->GetZoneInfoPacket(this);
  832. QueuePacket(packet);
  833. if (version > 561) {
  834. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  835. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  836. #if EQDEBUG >= 9
  837. fog_packet->PrintPacket();
  838. #endif
  839. if (fog_packet) {
  840. database.LoadFogInit(zone->GetZoneFile(), fog_packet);
  841. QueuePacket(fog_packet->serialize());
  842. safe_delete(fog_packet);
  843. }
  844. zone->SendFlightPathsPackets(this);
  845. }
  846. }
  847. /*
  848. uchar blah[] ={0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x01,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,0xFF,0xFF,0xFF,0xFF
  851. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  852. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00
  853. ,0x00,0x00,0x00,0x00,0x10,0x49,0x2B,0x62,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,0x00,0x00
  876. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  877. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  878. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0x00,0x00,0x00
  882. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  883. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00};
  884. EQ2Packet* appA = new EQ2Packet(OP_GuildUpdateMsg, blah, sizeof(blah));
  885. QueuePacket(appA);
  886. uchar blahA[] ={0x45,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00
  887. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  888. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  889. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00
  890. ,0x00,0x10,0xE2,0x10,0x6C,0x00,0x00,0x00,0x00};
  891. EQ2Packet* appB = new EQ2Packet(OP_KeymapDataMsg, blahA, sizeof(blahA));
  892. QueuePacket(appB);
  893. */
  894. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendFriendList");
  895. SendFriendList();
  896. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendIgnoreList");
  897. SendIgnoreList();
  898. }
  899. void Client::SendDefaultGroupOptions() {
  900. /*
  901. 0 - loot method
  902. 1 - loot items rarity
  903. 2 - Auto split coin
  904. 4 - default yell method
  905. 6 - group autolock
  906. 7 - solo autolock
  907. */
  908. PacketStruct* default_options = configReader.getStruct("WS_DefaultGroupOptions", GetVersion());
  909. if (default_options) {
  910. default_options->setDataByName("loot_method", GetPlayer()->GetInfoStruct()->get_group_loot_method());
  911. default_options->setDataByName("loot_items_rarity", GetPlayer()->GetInfoStruct()->get_group_loot_items_rarity());
  912. default_options->setDataByName("auto_split_coin", GetPlayer()->GetInfoStruct()->get_group_auto_split());
  913. default_options->setDataByName("default_yell_method", GetPlayer()->GetInfoStruct()->get_group_default_yell());
  914. default_options->setDataByName("group_autolock", GetPlayer()->GetInfoStruct()->get_group_autolock());
  915. default_options->setDataByName("default_group_lock_method", GetPlayer()->GetInfoStruct()->get_group_lock_method());
  916. if (GetVersion() > 561) {
  917. default_options->setDataByName("solo_autolock", GetPlayer()->GetInfoStruct()->get_group_solo_autolock());
  918. default_options->setDataByName("auto_loot_method", GetPlayer()->GetInfoStruct()->get_group_auto_loot_method());
  919. }
  920. EQ2Packet* app7 = default_options->serialize();
  921. QueuePacket(app7);
  922. safe_delete(default_options);
  923. }
  924. }
  925. bool Client::HandlePacket(EQApplicationPacket* app) {
  926. bool ret = true;
  927. //cout << "INCOMING PACKET!!!!!!!: " << app->GetOpcodeName() << endl;
  928. //DumpPacket(app);
  929. #if EQDEBUG >= 9
  930. LogWrite(PACKET__DEBUG, 9, "Packet", "[EQDEBUG] Received Packet:");
  931. DumpPacket(app, true);
  932. #endif
  933. EmuOpcode opcode = app->GetOpcode();
  934. #if EQDEBUG >= 9
  935. const char* name = app->GetOpcodeName();
  936. if (name)
  937. cout << name;
  938. else
  939. cout << "Unknown";
  940. cout << " Packet: OPCode: 0x" << hex << setw(2) << setfill('0') << app->GetOpcode() << dec << ", size: " << setw(5) << setfill(' ') << app->Size() << endl;
  941. DumpPacket(app);
  942. #endif
  943. //if (opcode != OP_UpdatePositionMsg) {
  944. // LogWrite(PACKET__DEBUG, 0, "opcode %s received", app->GetOpcodeName());
  945. //}
  946. if (!connected_to_zone && opcode != OP_LoginByNumRequestMsg)
  947. {
  948. opcode = _maxEmuOpcode; // skip since this is not a valid packet, sent before we allowed the login
  949. }
  950. switch (opcode) {
  951. case _maxEmuOpcode:
  952. break;
  953. case OP_LoginByNumRequestMsg: {
  954. LogWrite(OPCODE__DEBUG, 0, "Opcode", "Opcode 0x%X (%i): OP_LoginByNumRequestMsg", opcode, opcode);
  955. PacketStruct* request;
  956. request = configReader.getStruct("LoginByNumRequest", 1);
  957. if (request) {
  958. if (request->LoadPacketData(app->pBuffer, app->size)) {
  959. // test the original location of Version for clients older than 1212
  960. version = request->getType_int16_ByName("version");
  961. if (version == 0 || version >= 1208 || EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  962. // must be new client data version method, re-fetch the packet
  963. safe_delete(request);
  964. request = configReader.getStruct("LoginByNumRequest", 1208);
  965. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  966. // Xinux suggests using an INT16 here. Our first new version = 57000
  967. version = request->getType_int16_ByName("version");
  968. }
  969. else {
  970. LogWrite(LOGIN__ERROR, 0, "Login", "Nasty Horrible things happening. Tell a dev asap! Version: %i", version);
  971. break;
  972. }
  973. }
  974. if (EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  975. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  976. ClientPacketFunctions::SendLoginDenied(this);
  977. /* reset version and protect server from trying to send packets out to a bad client
  978. ** cause of Dec 6th/Dec 7th 2023 crash
  979. ** Client::MakeSpawnChangePacket
  980. ** int16 opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd); <-- crashes pulling opcode with bad version
  981. */
  982. version = 546;
  983. ready_for_updates = false;
  984. ready_for_spawns = false;
  985. return false;
  986. }
  987. int32 account_id = request->getType_int32_ByName("account_id");
  988. int32 access_code = request->getType_int32_ByName("access_code");
  989. if (!HandleNewLogin(account_id, access_code))
  990. return false;
  991. }
  992. }
  993. safe_delete(request);
  994. break;
  995. }
  996. case OP_DefaultGroupOptionsMsg: {
  997. PacketStruct* packet = configReader.getStruct("WS_DefaultGroupOptions", GetVersion());
  998. if (packet) {
  999. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1000. packet->PrintPacket();
  1001. int8 loot_method = packet->getType_int8_ByName("loot_method");
  1002. int8 loot_items_rarity = packet->getType_int8_ByName("loot_items_rarity");
  1003. if (GetVersion() <= 561)
  1004. loot_items_rarity = 0;
  1005. int8 auto_split_coin = packet->getType_int8_ByName("auto_split_coin");
  1006. int8 default_yell_method = packet->getType_int8_ByName("default_yell_method");
  1007. int8 autolock = packet->getType_int8_ByName("group_autolock");
  1008. int8 group_lock_method = packet->getType_int8_ByName("default_group_lock_method");
  1009. int8 solo_autolock = packet->getType_int8_ByName("solo_autolock");
  1010. int8 auto_loot_method = 0;
  1011. if (GetVersion() > 561) {
  1012. auto_loot_method = packet->getType_int8_ByName("auto_loot_method");
  1013. if (auto_loot_method > AutoLootMode::METHOD_DECLINE)
  1014. auto_loot_method = AutoLootMode::METHOD_DECLINE;
  1015. }
  1016. GetPlayer()->GetInfoStruct()->set_group_loot_method(loot_method);
  1017. GetPlayer()->GetInfoStruct()->set_group_loot_items_rarity(loot_items_rarity);
  1018. GetPlayer()->GetInfoStruct()->set_group_auto_split(auto_split_coin);
  1019. GetPlayer()->GetInfoStruct()->set_group_default_yell(default_yell_method);
  1020. GetPlayer()->GetInfoStruct()->set_group_autolock(autolock);
  1021. GetPlayer()->GetInfoStruct()->set_group_lock_method(group_lock_method);
  1022. GetPlayer()->GetInfoStruct()->set_group_solo_autolock(solo_autolock);
  1023. GetPlayer()->GetInfoStruct()->set_group_auto_loot_method(auto_loot_method);
  1024. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPLOOTMETHOD, (char*)std::to_string(loot_method).c_str());
  1025. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPLOOTITEMRARITY, (char*)std::to_string(loot_items_rarity).c_str());
  1026. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPAUTOSPLIT, (char*)std::to_string(auto_split_coin).c_str());
  1027. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPDEFAULTYELL, (char*)std::to_string(default_yell_method).c_str());
  1028. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPAUTOLOCK, (char*)std::to_string(autolock).c_str());
  1029. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPLOCKMETHOD, (char*)std::to_string(group_lock_method).c_str());
  1030. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPSOLOAUTOLOCK, (char*)std::to_string(solo_autolock).c_str());
  1031. database.insertCharacterProperty(this, CHAR_PROPERTY_AUTOLOOTMETHOD, (char*)std::to_string(auto_loot_method).c_str());
  1032. if (this->GetPlayer()->GetGroupMemberInfo() && this->GetPlayer()->GetGroupMemberInfo()->leader)
  1033. {
  1034. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  1035. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  1036. if (group)
  1037. {
  1038. bool isLeadGroup = group->IsInRaidGroup(group->GetID(), true);
  1039. bool isInRaid = group->IsInRaidGroup(group->GetID());
  1040. if (!isInRaid || isLeadGroup) {
  1041. GroupOptions goptions;
  1042. goptions.loot_method = loot_method;
  1043. goptions.loot_items_rarity = loot_items_rarity;
  1044. goptions.auto_split = auto_split_coin;
  1045. goptions.default_yell = default_yell_method;
  1046. goptions.group_autolock = autolock;
  1047. goptions.solo_autolock = solo_autolock;
  1048. goptions.auto_loot_method = auto_loot_method;
  1049. group->SetDefaultGroupOptions(&goptions);
  1050. // update group options with peers
  1051. std::vector<int32> raidGroups;
  1052. group->GetRaidGroups(&raidGroups);
  1053. std::vector<int32>::iterator group_itr;
  1054. for (group_itr = raidGroups.begin(); group_itr != raidGroups.end(); group_itr++) {
  1055. PlayerGroup* otherGroup = world.GetGroupManager()->GetGroup((*group_itr));
  1056. if (otherGroup)
  1057. otherGroup->SetDefaultGroupOptions(&goptions);
  1058. }
  1059. peer_manager.sendPeersNewGroupRequest("", 0, group->GetID(), "", "", &goptions, "", &raidGroups, true);
  1060. }
  1061. else {
  1062. SimpleMessage(CHANNEL_COLOR_YELLOW, "Group options may only be changed by raid leader.");
  1063. }
  1064. }
  1065. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  1066. }
  1067. }
  1068. safe_delete(packet);
  1069. }
  1070. break;
  1071. }
  1072. case OP_MapRequest: {
  1073. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapRequest", opcode, opcode);
  1074. PacketStruct* packet = configReader.getStruct("WS_MapRequest", GetVersion());
  1075. if (packet && app->size > 2 && GetCurrentZone()) {
  1076. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1077. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  1078. if (fog_packet) {
  1079. LogWrite(PACKET__DEBUG, 0, "Packet", "In OP_MapRequest: Fog Packet");
  1080. database.LoadFogInit(packet->getType_EQ2_16BitString_ByName("zone").data, fog_packet);
  1081. fog_packet->setDataByName("unknown1", 1);
  1082. fog_packet->setDataByName("unknown3", 1);
  1083. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1084. //fog_packet->PrintPacket();
  1085. QueuePacket(fog_packet->serialize());
  1086. safe_delete(fog_packet);
  1087. }
  1088. }
  1089. safe_delete(packet);
  1090. }
  1091. break;
  1092. }
  1093. case OP_RequestCampMsg: {
  1094. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RequestCampMsg", opcode, opcode);
  1095. PacketStruct* request = configReader.getStruct("WS_RequestCamp", GetVersion());
  1096. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  1097. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client '%s' (%u) is camping...", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  1098. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_RequestCamp - quit: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  1099. request->getType_int8_ByName("quit"),
  1100. request->getType_int8_ByName("camp_desktop"),
  1101. request->getType_int16_ByName("camp_char_select"),
  1102. (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? request->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  1103. //DumpPacket(app->pBuffer, app->size);
  1104. //request->PrintPacket();
  1105. if (!camp_timer) {
  1106. int16 camp_time = 20; // default if rule cannot be found
  1107. if (GetAdminStatus() >= 100)
  1108. camp_time = rule_manager.GetZoneRule(GetCurrentZoneID(), R_World, GMCampTimer)->GetInt16();
  1109. else
  1110. camp_time = rule_manager.GetZoneRule(GetCurrentZoneID(), R_World, PlayerCampTimer)->GetInt16();
  1111. PacketStruct* response = configReader.getStruct("WS_Camp", GetVersion());
  1112. if (response) {
  1113. bool disconnect = false;
  1114. if (request->getType_int8_ByName("camp_desktop") == 1 && request->getType_int8_ByName("quit") == 1) {
  1115. // Command: /camp desktop
  1116. // Command: /quit
  1117. response->setDataByName("camp_desktop", 1);
  1118. disconnect = true;
  1119. }
  1120. else {
  1121. // Command: /camp
  1122. response->setDataByName("camp_desktop", request->getType_int8_ByName("camp_desktop"));
  1123. response->setDataByName("camp_char_select", request->getType_int16_ByName("camp_char_select"));
  1124. response->setDataByName("seconds", camp_time);
  1125. }
  1126. camp_timer = new Timer(camp_time * 1000);
  1127. camp_timer->Enable();
  1128. if (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) {
  1129. // /camp {char_name}
  1130. response->setDataByName("char_name", request->getType_EQ2_16BitString_ByName("char_name").data.c_str());
  1131. }
  1132. else if (request->getType_int8_ByName("camp_desktop") == 0 && request->getType_int16_ByName("camp_char_select") == 0) {
  1133. // /camp (go back to char selection screen)
  1134. response->setDataByName("char_name", " ");
  1135. response->setDataByName("camp_char_select", 1);
  1136. }
  1137. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_Camp - seconds: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  1138. response->getType_int8_ByName("seconds"),
  1139. response->getType_int8_ByName("camp_desktop"),
  1140. response->getType_int8_ByName("camp_char_select"),
  1141. (response->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? response->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  1142. // JA: trying to recognize /camp vs LD (see ZoneServer::ClientProcess())
  1143. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0)
  1144. player->SetActivityStatus(player->GetActivityStatus() + ACTIVITY_STATUS_CAMPING);
  1145. //response->PrintPacket();
  1146. QueuePacket(response->serialize());
  1147. safe_delete(response);
  1148. if (disconnect)
  1149. Disconnect();
  1150. }
  1151. }
  1152. }
  1153. safe_delete(request);
  1154. break;
  1155. }
  1156. case OP_StoodMsg: {
  1157. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StoodMsg", opcode, opcode);
  1158. if (camp_timer)
  1159. {
  1160. // JA: clear camping flag
  1161. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1162. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1163. safe_delete(camp_timer);
  1164. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1165. QueuePacket(outapp);
  1166. }
  1167. player->SetTempVisualState(0);
  1168. break;
  1169. }
  1170. case OP_StandMsg: {
  1171. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StandMsg", opcode, opcode);
  1172. if (camp_timer)
  1173. {
  1174. // JA: clear camping flag
  1175. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1176. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1177. safe_delete(camp_timer);
  1178. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1179. QueuePacket(outapp);
  1180. }
  1181. player->SetTempVisualState(539);
  1182. break;
  1183. }
  1184. case OP_SitMsg: {
  1185. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SitMsg", opcode, opcode);
  1186. player->SetTempVisualState(538);
  1187. break;
  1188. }
  1189. case OP_SatMsg: {
  1190. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SatMsg", opcode, opcode);
  1191. player->SetTempVisualState(540);
  1192. break;
  1193. }
  1194. case OP_QuestJournalOpenMsg:
  1195. case OP_QuestJournalInspectMsg: {
  1196. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalOpenMsg, OP_QuestJournalInspectMsg", opcode, opcode);
  1197. if (app->size < sizeof(int32))
  1198. break;
  1199. int32 quest_id = 0;
  1200. memcpy(&quest_id, app->pBuffer, sizeof(int32));
  1201. GetPlayer()->SendQuest(quest_id);
  1202. break;
  1203. }
  1204. case OP_QuestJournalSetVisibleMsg: {
  1205. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalSetVisibleMsg", opcode, opcode);
  1206. PacketStruct* packet = configReader.getStruct("WS_QuestJournalVisible", GetVersion());
  1207. if (packet) {
  1208. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1209. int32 quest_id = packet->getType_int32_ByName("quest_id");
  1210. bool hidden = packet->getType_int8_ByName("visible") == 1 ? false : true;
  1211. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  1212. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  1213. if (player_quests) {
  1214. if (player_quests->count(quest_id) > 0)
  1215. player_quests->at(quest_id)->SetHidden(hidden);
  1216. else
  1217. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Player does not have quest with id of %u", quest_id);
  1218. }
  1219. else
  1220. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Unable to get player(%s) quests", player->GetName());
  1221. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  1222. }
  1223. safe_delete(packet);
  1224. }
  1225. break;
  1226. }
  1227. case OP_MacroUpdateMsg: {
  1228. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MacroUpdateMsg", opcode, opcode);
  1229. PacketStruct* macro_update = configReader.getStruct("WS_MacroUpdate", GetVersion());
  1230. if (macro_update) {
  1231. if (macro_update->LoadPacketData(app->pBuffer, app->size)) {
  1232. vector<string>* update = new vector<string>;
  1233. int8 number = macro_update->getType_int8_ByName("number");
  1234. int16 icon = macro_update->getType_int16_ByName("icon");
  1235. string name = macro_update->getType_EQ2_8BitString_ByName("name").data;
  1236. int8 count = macro_update->getType_int8_ByName("macro_count");
  1237. if (GetVersion() <= 373) {
  1238. update->push_back(macro_update->getType_EQ2_8BitString_ByName("command").data);
  1239. }
  1240. else {
  1241. for (int8 i = 0; i < count; i++) {
  1242. char tmp_command[15] = { 0 };
  1243. sprintf(tmp_command, "command_%i", i);
  1244. update->push_back(macro_update->getType_EQ2_16BitString_ByName(tmp_command).data);
  1245. }
  1246. }
  1247. if (name.length() == 0)
  1248. database.UpdateCharacterMacro(GetCharacterID(), number, 0, icon, update);
  1249. else
  1250. database.UpdateCharacterMacro(GetCharacterID(), number, name.c_str(), icon, update);
  1251. safe_delete(update);
  1252. }
  1253. safe_delete(macro_update);
  1254. }
  1255. break;
  1256. }
  1257. case OP_DialogSelectMsg: {
  1258. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DialogSelectMsg", opcode, opcode);
  1259. PacketStruct* packet = configReader.getStruct("WS_DialogSelect", GetVersion());
  1260. if (packet) {
  1261. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1262. int32 conversation_id = packet->getType_int32_ByName("conversation_id");
  1263. int32 response_index = packet->getType_int32_ByName("response");
  1264. HandleDialogSelectMsg(conversation_id, response_index);
  1265. }
  1266. }
  1267. safe_delete(packet);
  1268. break;
  1269. }
  1270. case OP_CancelMoveObjectModeMsg: {
  1271. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1272. if (GetTempPlacementSpawn())
  1273. {
  1274. Spawn* tmp = GetTempPlacementSpawn();
  1275. SetTempPlacementSpawn(nullptr);
  1276. SetPlacementUniqueItemID(0);
  1277. GetCurrentZone()->RemoveSpawn(tmp, true, false, true, true, true);
  1278. break; // break out early if we are tied to a temp spawn
  1279. }
  1280. // if we are moving some other object? other use-cases not covered
  1281. break;
  1282. }
  1283. case OP_PositionMoveableObject: {
  1284. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PositionMoveableObject", opcode, opcode);
  1285. PacketStruct* place_object = configReader.getStruct("WS_PlaceMoveableObject", GetVersion());
  1286. if (place_object && place_object->LoadPacketData(app->pBuffer, app->size)) {
  1287. Spawn* spawn = 0;
  1288. bool was_temp_placement = false;
  1289. if (GetTempPlacementSpawn()) {
  1290. spawn = GetTempPlacementSpawn();
  1291. was_temp_placement = true;
  1292. }
  1293. else
  1294. spawn = GetPlayer()->GetSpawnWithPlayerID(place_object->getType_int32_ByName("spawn_id"));
  1295. if (!spawn) {
  1296. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn.");
  1297. break;
  1298. }
  1299. else if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE && !HasOwnerOrEditAccess())
  1300. {
  1301. SimpleMessage(CHANNEL_COLOR_RED, "This is not your home!");
  1302. break;
  1303. }
  1304. int32 uniqueID = spawn->GetPickupUniqueItemID();
  1305. if (uniqueID) {
  1306. Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  1307. if (uniqueItem && uniqueItem->CheckFlag2(HOUSE_LORE) && GetCurrentZone()->HouseItemSpawnExists(uniqueItem->details.item_id)) {
  1308. Message(CHANNEL_COLOR_RED, "Item %s is house lore and you cannot place another.", uniqueItem->name.c_str());
  1309. break;
  1310. }
  1311. }
  1312. // handles instantiation logic + adding to zone of a new house object
  1313. PopulateHouseSpawn(place_object);
  1314. float newHeading = place_object->getType_float_ByName("heading") + 180;
  1315. char query[256];
  1316. switch (GetSpawnPlacementMode())
  1317. {
  1318. case ServerSpawnPlacementMode::OPEN_HEADING:
  1319. {
  1320. if (spawn && spawn->IsWidget())
  1321. {
  1322. Widget* widget = (Widget*)spawn;
  1323. widget->SetOpenHeading(newHeading);
  1324. widget->SetIncludeHeading(true);
  1325. spawn->position_changed = true;
  1326. _snprintf(query, 256, "open_heading=%f,include_heading=1", newHeading);
  1327. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1328. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget open heading information.");
  1329. }
  1330. else
  1331. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1332. break;
  1333. }
  1334. case ServerSpawnPlacementMode::CLOSE_HEADING:
  1335. {
  1336. if (spawn && spawn->IsWidget())
  1337. {
  1338. Widget* widget = (Widget*)spawn;
  1339. widget->SetClosedHeading(newHeading);
  1340. widget->SetIncludeHeading(true);
  1341. spawn->position_changed = true;
  1342. _snprintf(query, 256, "closed_heading=%f,include_heading=1", newHeading);
  1343. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1344. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget close heading information.");
  1345. if (spawn->GetSpawnLocationID())
  1346. {
  1347. Query query;
  1348. query.RunQuery2(Q_INSERT, "update spawn_location_placement set heading = %f where id = %u", newHeading, spawn->GetSpawnLocationID());
  1349. }
  1350. }
  1351. else
  1352. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1353. break;
  1354. }
  1355. default:
  1356. {
  1357. spawn->SetX(place_object->getType_float_ByName("x"));
  1358. spawn->SetY(place_object->getType_float_ByName("y"));
  1359. spawn->SetZ(place_object->getType_float_ByName("z"));
  1360. spawn->SetHeading(newHeading);
  1361. spawn->SetSpawnOrigX(spawn->GetX());
  1362. spawn->SetSpawnOrigY(spawn->GetY());
  1363. spawn->SetSpawnOrigZ(spawn->GetZ());
  1364. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1365. if (spawn->GetSpawnLocationID() > 0 && database.UpdateSpawnLocationSpawns(spawn)) {
  1366. if (!was_temp_placement) {
  1367. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved spawn information.");
  1368. }
  1369. }
  1370. else if (spawn->GetSpawnLocationID() > 0) {
  1371. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn information, see console window for details.");
  1372. }
  1373. }
  1374. }
  1375. PopulateHouseSpawnFinalize();
  1376. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1377. }
  1378. safe_delete(place_object);
  1379. break;
  1380. }
  1381. case OP_CampAbortedMsg: {
  1382. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CampAbortedMsg", opcode, opcode);
  1383. if (camp_timer)
  1384. {
  1385. // JA: clear camping flag
  1386. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1387. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1388. safe_delete(camp_timer);
  1389. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1390. QueuePacket(outapp);
  1391. }
  1392. break;
  1393. }
  1394. case OP_DoneLoadingUIResourcesMsg: {
  1395. if (GetVersion() <= 561) {
  1396. ClientPacketFunctions::SendUpdateSpellBook(this);
  1397. }
  1398. // need to quickly flash the DoF client the rest of their inventory
  1399. if (GetVersion() <= 561) {
  1400. EQ2Packet* item_app = player->GetPlayerItemList()->serialize(GetPlayer(), GetVersion());
  1401. if (item_app) {
  1402. QueuePacket(item_app);
  1403. }
  1404. }
  1405. EQ2Packet* app = new EQ2Packet(OP_DoneLoadingUIResourcesMsg, 0, 0);
  1406. QueuePacket(app);
  1407. if (!player_loading_complete)
  1408. {
  1409. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  1410. if (zone_script && lua_interface)
  1411. lua_interface->RunZoneScript(zone_script, "player_loadcomplete", GetCurrentZone(), GetPlayer());
  1412. player_loading_complete = true;
  1413. }
  1414. break;
  1415. }
  1416. case OP_DoneLoadingZoneResourcesMsg: {
  1417. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingZoneResourcesMsg", opcode, opcode);
  1418. SendZoneSpawns();
  1419. break;
  1420. }
  1421. case OP_DefaultGroupOptionsRequestMsg: {
  1422. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DefaultGroupOptionsRequestMsg", opcode, opcode);
  1423. SendDefaultGroupOptions();
  1424. break;
  1425. }
  1426. case OP_DoneLoadingEntityResourcesMsg: {
  1427. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingEntityResourcesMsg", opcode, opcode);
  1428. if (!IsReadyForSpawns()) {
  1429. if (GetPlayer()->GetMap()) {
  1430. auto loc = glm::vec3(GetPlayer()->GetX(), GetPlayer()->GetZ(), GetPlayer()->GetY());
  1431. uint32 GridID = 0;
  1432. float new_z = GetPlayer()->FindBestZ(loc, nullptr, &GridID);
  1433. GetPlayer()->SetLocation(GridID);
  1434. }
  1435. SetReadyForSpawns(true);
  1436. }
  1437. player->CalculateApplyWeight();
  1438. SendCharInfo();
  1439. GetPlayer()->GetZone()->GetSpellProcess()->SendSpellBookUpdate(this);
  1440. pos_update.Start();
  1441. quest_pos_timer.Start();
  1442. break;
  1443. }
  1444. case OP_LootItemsRequestMsg: {
  1445. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_LootItemsRequestMsg", opcode, opcode);
  1446. HandleLootItemRequestPacket(app);
  1447. break;
  1448. }
  1449. case OP_StoppedLootingMsg: {
  1450. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StoppedLootingMsg", opcode, opcode);
  1451. if (app->size < sizeof(int32))
  1452. break;
  1453. int32 loot_id = 0;
  1454. memcpy(&loot_id, app->pBuffer, sizeof(int32));
  1455. Spawn* spawn = GetCurrentZone()->GetSpawnByID(loot_id);
  1456. if (spawn) {
  1457. spawn->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
  1458. spawn->SetLooterSpawnID(0);
  1459. }
  1460. break;
  1461. }
  1462. case OP_WaypointSelectMsg: {
  1463. PacketStruct* packet = configReader.getStruct("WS_WaypointSelect", GetVersion());
  1464. if (packet) {
  1465. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1466. int32 selection = packet->getType_int32_ByName("selection");
  1467. if (selection > 0) {
  1468. SelectWaypoint(selection);
  1469. }
  1470. }
  1471. }
  1472. safe_delete(packet);
  1473. break;
  1474. }
  1475. case OP_KnowledgeWindowSlotMappingMsg: {
  1476. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_KnowledgeWindowSlotMappingMsg", opcode, opcode);
  1477. PacketStruct* packet = configReader.getStruct("WS_SpellSlotMapping", GetVersion());
  1478. if (packet) {
  1479. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1480. int num_updates = packet->getType_int16_ByName("spell_count");
  1481. int32 spell_id = 0;
  1482. int16 slot_id = 0;
  1483. char tmp_spell_id[15];
  1484. char tmp_slot[15];
  1485. for (int i = 0; i < num_updates; i++) {
  1486. memset(tmp_spell_id, 0, 15);
  1487. memset(tmp_slot, 0, 15);
  1488. sprintf(tmp_spell_id, "spell_id_%i", i);
  1489. sprintf(tmp_slot, "slot_id_%i", i);
  1490. spell_id = packet->getType_int32_ByName(tmp_spell_id);
  1491. if (spell_id > 0) {
  1492. slot_id = packet->getType_int16_ByName(tmp_slot);
  1493. SpellBookEntry* spell = player->GetSpellBookSpell(spell_id);
  1494. if (spell && spell->slot != slot_id) {
  1495. spell->slot = slot_id;
  1496. spell->save_needed = true;
  1497. }
  1498. }
  1499. }
  1500. }
  1501. safe_delete(packet);
  1502. }
  1503. //SendKnowledgeWindowSlot();
  1504. break;
  1505. }
  1506. case OP_ReadyToZoneMsg: {
  1507. if (!IsReadyForSpawns())
  1508. {
  1509. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s is logging into zone, skipping disconnect.");
  1510. }
  1511. else
  1512. {
  1513. if (zoning_destination) {
  1514. SetCurrentZone(zoning_destination);
  1515. }
  1516. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyToZoneMsg", opcode, opcode);
  1517. if (client_zoning)
  1518. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s zoning to %u, instance id %u", player->GetName(), zoning_id, zoning_instance_id);
  1519. else
  1520. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone without server authorization.", player->GetName());
  1521. Disconnect();
  1522. }
  1523. break;
  1524. }
  1525. case OP_ClientFellMsg: {
  1526. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ClientFellMsg (ouch!)", opcode, opcode);
  1527. PacketStruct* request = configReader.getStruct("WS_ClientFell", GetVersion());
  1528. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  1529. float height = request->getType_float_ByName("height");
  1530. /*int32 spawn_id = request->getType_int32_ByName("spawn_id");
  1531. if(GetPlayer()->GetSpawnWithPlayerID(spawn_id) != GetPlayer()){
  1532. cout << "Error: " << GetPlayer()->GetName() << " called ClientFell with an invalid ID of: " << spawn_id << endl;
  1533. break;
  1534. }*/
  1535. float safe_height = 13.0f;
  1536. float safe_skill_with_bonus = GetPlayer()->CalculateSkillWithBonus("Safe Fall", ITEM_STAT_SAFE_FALL, true);
  1537. if (safe_skill_with_bonus > 0.0f)
  1538. safe_height += (1 + safe_skill_with_bonus) / 5;
  1539. if (height > safe_height) {
  1540. int16 damage = (int16)ceil((height - safe_height) * 125);
  1541. if (height >= 80)
  1542. damage = 30000;
  1543. //cout << "Detected fall height:" << height << " damage:" << damage << endl;
  1544. if (damage > 0) {
  1545. GetPlayer()->TakeDamage(damage);
  1546. if (GetPlayer()->GetPlayerStatisticValue(STAT_PLAYER_HIGHEST_FALLING_HIT) < damage)
  1547. GetPlayer()->UpdatePlayerStatistic(STAT_PLAYER_HIGHEST_FALLING_HIT, damage, true);
  1548. if (!GetPlayer()->GetInvulnerable())
  1549. GetPlayer()->SetCharSheetChanged(true);
  1550. 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);
  1551. if (GetPlayer()->GetHP() == 0) {
  1552. GetCurrentZone()->KillSpawn(false, GetPlayer(), 0);
  1553. }
  1554. }
  1555. }
  1556. }
  1557. safe_delete(request);
  1558. break;
  1559. }
  1560. case OP_MapFogDataUpdateMsg: {
  1561. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapFogDataUpdateMsg", opcode, opcode);
  1562. LogWrite(MISC__TODO, 3, "TODO", "Handle (OP_MapFogDataUpdateMsg), ignoring it for now\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1563. break;
  1564. }
  1565. case OP_SelectZoneTeleporterDestinatio: {
  1566. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SelectZoneTeleporterDestinatio", opcode, opcode);
  1567. ProcessTeleportLocation(app);
  1568. break;
  1569. }
  1570. case OP_SendLatestRequestMsg: {
  1571. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SendLatestRequestMsg", opcode, opcode);
  1572. if (GetVersion() < 60085) {
  1573. // this does not exist in newer clients like AoM, confirmed to exist in DoF, other clients will need review at a later time
  1574. uchar blah25[] = { 0x01 };
  1575. EQ2Packet* app25 = new EQ2Packet(OP_ClearDataMsg, blah25, sizeof(blah25));
  1576. QueuePacket(app25);
  1577. }
  1578. break;
  1579. }
  1580. case OP_RequestRecipeDetailsMsg: {
  1581. PacketStruct* packet = configReader.getStruct("WS_RequestRecipeDetail", GetVersion());
  1582. if (packet) {
  1583. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1584. vector<int32> recipes;
  1585. int32 recipe_id = 0;
  1586. char recipe_prop_name[30];
  1587. int32 num_recipes = packet->getType_int32_ByName("num_recipes");
  1588. // WS_RecipeDetails
  1589. for (int32 i = 0; i < num_recipes; i++) {
  1590. memset(recipe_prop_name, 0, 30);
  1591. snprintf(recipe_prop_name, 30, "recipe_id_%i", i);
  1592. recipe_id = packet->getType_int32_ByName(recipe_prop_name);
  1593. if (recipe_id > 0) {
  1594. recipes.push_back(recipe_id);
  1595. }
  1596. }
  1597. SendRecipeDetails(&recipes);
  1598. }
  1599. safe_delete(packet);
  1600. }
  1601. break;
  1602. }
  1603. case OP_ShowCreateFromRecipeUIMsg: {
  1604. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ShowCreateFromRecipeUIMsg", opcode, opcode);
  1605. break;
  1606. /*uchar blah[] ={0x09,0x0e,0x00,0x51,0x75,0x65,0x65,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e
  1607. ,0x79,0x00,0x00,0x00,0x00,0x40,0x40,0xff,0xff,0xff};
  1608. EQ2Packet* app = new EQ2Packet(OP_EncounterBrokenMsg, blah, sizeof(blah));
  1609. QueuePacket(app);
  1610. uchar blah2[] = {0x00,0x00,0xff,0xff,0xff,0xff};
  1611. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah2, sizeof(blah2));
  1612. QueuePacket(app);
  1613. uchar blah3[] ={0x09,0x17,0x00,0x5c,0x23,0x46,0x46,0x45,0x34,0x30,0x30,0x20,0x51,0x75,0x65,0x65
  1614. ,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e,0x79,0x00,0x00,0x00,0x00,0xa0,0x40
  1615. ,0xff,0xff,0xff};
  1616. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah3, sizeof(blah3));
  1617. QueuePacket(app);
  1618. uchar blah4[] ={0x0b,0x00,0x21,0x00,0x00,0x00,0x1d,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17
  1619. ,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81
  1620. ,0x42,0x17,0x81,0x42,0x17,0x81,0x42};
  1621. app = new EQ2Packet(OP_UpdateSpellBookMsg, blah4, sizeof(blah4));
  1622. QueuePacket(app);
  1623. uchar blah5[] ={0x00,0x00};
  1624. app = new EQ2Packet(OP_RecipeDetailsMsg, blah5, sizeof(blah5));
  1625. QueuePacket(app);
  1626. break;*/
  1627. //player->GetPlayerInfo()->GetInfo()->cur_power = 100;
  1628. //EQ2Packet* app = player->GetPlayerInfo()->serialize(1);
  1629. //QueuePacket(app);
  1630. }
  1631. case OP_BeginItemCreationMsg: {
  1632. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginItemCreationMsg", opcode, opcode);
  1633. //DumpPacket(app->pBuffer, app->size);
  1634. PacketStruct* packet = configReader.getStruct("WS_BeginItemCreation", GetVersion());
  1635. if (packet) {
  1636. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1637. Recipe* recipe = master_recipe_list.GetRecipe(GetPlayer()->GetCurrentRecipe());
  1638. if (recipe) {
  1639. int32 item = 0;
  1640. int8 qty = 0;
  1641. vector<pair<int32, int16>> items;
  1642. char tmp_item_id[30];
  1643. if (GetVersion() > 1193) {
  1644. int8 num_primary_selected_items = packet->getType_int8_ByName("num_primary_selected_items");
  1645. for (int8 i = 0; i < num_primary_selected_items; i++) {
  1646. memset(tmp_item_id, 0, 30);
  1647. sprintf(tmp_item_id, "primary_selected_item_id_%i", i);
  1648. item = packet->getType_int32_ByName(tmp_item_id);
  1649. sprintf(tmp_item_id, "primary_selected_item_qty_%i", i);
  1650. qty = packet->getType_int16_ByName(tmp_item_id);
  1651. if (item > 0)
  1652. items.push_back(make_pair(item, qty));
  1653. item = 0;
  1654. }
  1655. }
  1656. else {
  1657. item = packet->getType_int32_ByName("primary_component_id");
  1658. qty = 1;
  1659. if (item > 0)
  1660. items.push_back(make_pair(item, qty));
  1661. }
  1662. int8 build_components = packet->getType_int8_ByName("num_build_components");
  1663. if (GetVersion() > 1193) {
  1664. for (int8 i = 0; i < build_components; i++) {
  1665. memset(tmp_item_id, 0, 30);
  1666. sprintf(tmp_item_id, "num_selected_items_%i", i);
  1667. int8 num_selected_items = packet->getType_int8_ByName(tmp_item_id);
  1668. for (int8 j = 0; j < num_selected_items; j++) {
  1669. memset(tmp_item_id, 0, 30);
  1670. sprintf(tmp_item_id, "selected_id%i_%i", i, j);
  1671. item = packet->getType_int32_ByName(tmp_item_id);
  1672. sprintf(tmp_item_id, "selected_qty%i_%i", i, j);
  1673. qty = packet->getType_int16_ByName(tmp_item_id);
  1674. if (item > 0)
  1675. items.push_back(make_pair(item, qty));
  1676. item = 0;
  1677. }
  1678. }
  1679. }
  1680. else {
  1681. for (int8 i = 0; i < build_components; i++) {
  1682. memset(tmp_item_id, 0, 30);
  1683. sprintf(tmp_item_id, "component_id_%i", i);
  1684. int32 item = packet->getType_int32_ByName(tmp_item_id);
  1685. sprintf(tmp_item_id, "component_qty_%i", i);
  1686. qty = packet->getType_int32_ByName(tmp_item_id);
  1687. if (item > 0)
  1688. items.push_back(make_pair(item, qty));
  1689. }
  1690. }
  1691. if (GetVersion() > 1193) {
  1692. int8 num_fuel_items = packet->getType_int8_ByName("num_fuel_items");
  1693. for (int8 i = 0; i < num_fuel_items; i++) {
  1694. memset(tmp_item_id, 0, 30);
  1695. sprintf(tmp_item_id, "fuel_id_%i", i);
  1696. item = packet->getType_int32_ByName(tmp_item_id);
  1697. sprintf(tmp_item_id, "fuel_qty_%i", i);
  1698. qty = packet->getType_int16_ByName(tmp_item_id);
  1699. if (item > 0)
  1700. items.push_back(make_pair(item, qty));
  1701. item = 0;
  1702. }
  1703. }
  1704. else {
  1705. item = packet->getType_int32_ByName("fuel_id");
  1706. qty = packet->getType_int16_ByName("fuel_qty");
  1707. if (item > 0)
  1708. items.push_back(make_pair(item, qty));
  1709. }
  1710. GetCurrentZone()->GetTradeskillMgr()->BeginCrafting(this, items);
  1711. }
  1712. else {
  1713. LogWrite(CCLIENT__ERROR, 0, "Client", "Client '%s' (%u) attempted to call OP_BeginItemCreationMsg, but with no recipe selected.", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  1714. }
  1715. }
  1716. safe_delete(packet);
  1717. }
  1718. break;
  1719. }
  1720. case OP_StopItemCreationMsg: {
  1721. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopItemCreationMsg", opcode, opcode);
  1722. //DumpPacket(app->pBuffer, app->size);
  1723. GetCurrentZone()->GetTradeskillMgr()->StopCrafting(this);
  1724. break;
  1725. }
  1726. case OP_SysClient:
  1727. case OP_SignalMsg: {
  1728. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SysClient/OP_SignalMsg", opcode, opcode);
  1729. PacketStruct* packet = configReader.getStruct("WS_Signal", 1);
  1730. if (packet) {
  1731. if (packet->LoadPacketData(app->pBuffer, app->size) && player->GetZone()) {
  1732. EQ2_16BitString str = packet->getType_EQ2_16BitString_ByName("signal");
  1733. if (strcmp(str.data.c_str(), "sys_client_avatar_ready") == 0) {
  1734. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client '%s' (%u) is ready for spawn updates.", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  1735. SetReloadingZone(false);
  1736. if (GetPlayer()->IsDeletedSpawn()) {
  1737. GetPlayer()->SetDeletedSpawn(false);
  1738. }
  1739. ResetZoningCoords();
  1740. SetReadyForUpdates();
  1741. GetPlayer()->SendSpawnChanges(true);
  1742. ProcessStateCommands();
  1743. GetPlayer()->changed = true;
  1744. GetPlayer()->info_changed = true;
  1745. GetPlayer()->vis_changed = true;
  1746. player_pos_changed = true;
  1747. GetPlayer()->AddChangedZoneSpawn();
  1748. ProcessZoneIgnoreWidgets();
  1749. if (version <= 561) {
  1750. master_trait_list.ChooseNextTrait(this);
  1751. }
  1752. const char* zone_script = world.GetZoneScript(GetPlayer()->GetZone()->GetZoneID());
  1753. if (zone_script && lua_interface) {
  1754. lua_interface->RunZoneScript(zone_script, "enter_location", GetPlayer()->GetZone(), GetPlayer(), GetPlayer()->GetLocation());
  1755. }
  1756. if (GetPlayer()->GetHP() < GetPlayer()->GetTotalHP() || GetPlayer()->GetPower() < GetPlayer()->GetTotalPower())
  1757. GetCurrentZone()->AddDamagedSpawn(GetPlayer());
  1758. }
  1759. else {
  1760. LogWrite(CCLIENT__WARNING, 0, "Client", "Player %s reported SysClient/SignalMsg state %s.", GetPlayer()->GetName(), str.data.c_str());
  1761. }
  1762. const char* zone_script = world.GetZoneScript(player->GetZone()->GetZoneID());
  1763. if (zone_script && lua_interface)
  1764. {
  1765. lua_interface->RunZoneScript(zone_script, "signal_changed", player->GetZone(), player, 0, str.data.c_str());
  1766. }
  1767. }
  1768. safe_delete(packet);
  1769. }
  1770. break;
  1771. }
  1772. case OP_EntityVerbsRequestMsg: {
  1773. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsRequestMsg", opcode, opcode);
  1774. HandleVerbRequest(app);
  1775. break;
  1776. }
  1777. case OP_EntityVerbsVerbMsg: {
  1778. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsVerbMsg", opcode, opcode);
  1779. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsVerb", GetVersion());
  1780. if (packet) {
  1781. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1782. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1783. Spawn* spawn = player->GetSpawnWithPlayerID(spawn_id); // fixed using GetTarget and the target was never set causing commands not to work
  1784. player->SetTarget(spawn);
  1785. if (spawn && !spawn->IsNPC() && !spawn->IsPlayer()) {
  1786. string command = packet->getType_EQ2_16BitString_ByName("command").data;
  1787. if (!HandleHouseEntityCommands(spawn, spawn_id, command))
  1788. {
  1789. if (EntityCommandPrecheck(spawn, command.c_str())) {
  1790. if (spawn->IsGroundSpawn())
  1791. ((GroundSpawn*)spawn)->HandleUse(this, command);
  1792. else if (spawn->IsObject())
  1793. ((Object*)spawn)->HandleUse(this, command);
  1794. else if (spawn->IsWidget())
  1795. ((Widget*)spawn)->HandleUse(this, command);
  1796. else if (spawn->IsSign())
  1797. ((Sign*)spawn)->HandleUse(this, command);
  1798. }
  1799. }
  1800. }
  1801. else {
  1802. EQ2_16BitString command = packet->getType_EQ2_16BitString_ByName("command");
  1803. if (command.size > 0) {
  1804. string command_name = command.data;
  1805. if (command_name.find(" ") < 0xFFFFFFFF) {
  1806. if (GetVersion() <= 561) { //this version uses commands in the form "Buy From Merchant" instead of buy_from_merchant
  1807. string::size_type pos = command_name.find(" ");
  1808. while (pos != string::npos) {
  1809. command_name.replace(pos, 1, "_");
  1810. pos = command_name.find(" ");
  1811. }
  1812. }
  1813. else
  1814. command_name = command_name.substr(0, command_name.find(" "));
  1815. }
  1816. int32 handler = commands.GetCommandHandler(command_name.c_str());
  1817. if (handler != 0xFFFFFFFF) {
  1818. if (command.data == command_name) {
  1819. command.data = "";
  1820. command.size = 0;
  1821. }
  1822. else {
  1823. command.data = command.data.substr(command.data.find(" ") + 1);
  1824. command.size = command.data.length();
  1825. }
  1826. commands.Process(handler, &command, this);
  1827. }
  1828. else {
  1829. if (spawn && spawn->IsNPC()) {
  1830. if (EntityCommandPrecheck(spawn, command.data.c_str())) {
  1831. if (!((NPC*)spawn)->HandleUse(this, command.data)) {
  1832. command_name = command.data;
  1833. string::size_type pos = command_name.find(" ");
  1834. while (pos != string::npos) {
  1835. command_name.replace(pos, 1, "_");
  1836. pos = command_name.find(" ");
  1837. }
  1838. if (!((NPC*)spawn)->HandleUse(this, command_name)) { //convert the spaces to underscores and see if that makes a difference
  1839. LogWrite(WORLD__ERROR, 0, "World", "Unhandled command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1840. }
  1841. }
  1842. }
  1843. }
  1844. else
  1845. LogWrite(WORLD__ERROR, 0, "World", "Unknown command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1846. }
  1847. }
  1848. }
  1849. }
  1850. safe_delete(packet);
  1851. }
  1852. break;
  1853. }
  1854. case OP_SkillInfoRequest: {
  1855. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SkillInfoRequest", opcode, opcode);
  1856. HandleSkillInfoRequest(app);
  1857. break;
  1858. }
  1859. case OP_UpdateTargetMsg: {
  1860. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_UpdateTargetMsg", opcode, opcode);
  1861. int16 index = 0;
  1862. memcpy(&index, app->pBuffer, sizeof(int16));
  1863. if (index == 0xFFFF)
  1864. GetPlayer()->SetTarget(0);
  1865. else {
  1866. Spawn* spawn = GetPlayer()->GetSpawnByIndex(index);
  1867. if (spawn)
  1868. GetPlayer()->SetTarget(spawn);
  1869. else {
  1870. LogWrite(PLAYER__ERROR, 1, "Player", "Player %s tried to target %u index, but that index was not valid.", GetPlayer()->GetName(), index);
  1871. }
  1872. }
  1873. if (GetPlayer()->GetTarget())
  1874. GetCurrentZone()->CallSpawnScript(GetPlayer()->GetTarget(), SPAWN_SCRIPT_TARGETED, GetPlayer());
  1875. //player->SetTarget((int16*)app->pBuffer);
  1876. break;
  1877. }
  1878. case OP_ExamineInfoRequestMsg: {
  1879. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExamineInfoRequestMsg", opcode, opcode);
  1880. HandleExamineInfoRequest(app);
  1881. break;
  1882. }
  1883. case OP_QuickbarUpdateMsg:
  1884. //case OP_QuickbarAddMsg:
  1885. {
  1886. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuickbarUpdateMsg, OP_QuickbarAddMsg", opcode, opcode);
  1887. HandleQuickbarUpdateRequest(app);
  1888. break;
  1889. }
  1890. case OP_PredictionUpdateMsg: {
  1891. LogWrite(OPCODE__DEBUG, 7, "Opcode", "Opcode 0x%X (%i): OP_PredictionUpdateMsg from %s", opcode, opcode, GetPlayer()->GetName());
  1892. if (version <= 561 && GetPlayer() && GetPlayer()->GetZone()) {
  1893. int8 offset = 9;
  1894. if (app->pBuffer[0] == 0xFF)
  1895. offset += 2;
  1896. if (app->size > offset) {
  1897. if (player->IsCasting()) {
  1898. float distance = 0;
  1899. float x = player->GetX();
  1900. float y = player->GetY();
  1901. float z = player->GetZ();
  1902. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1903. distance = player->GetDistance(x, y, z, false);
  1904. if (distance > .5)
  1905. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1906. }
  1907. else
  1908. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1909. player_pos_changed = true;
  1910. GetPlayer()->changed = true;
  1911. GetPlayer()->info_changed = true;
  1912. GetPlayer()->vis_changed = true;
  1913. GetPlayer()->AddChangedZoneSpawn();
  1914. //DumpPacket(app);
  1915. }
  1916. }
  1917. else {
  1918. EQ2Packet* app = new EQ2Packet(OP_PredictionUpdateMsg, 0, 0);
  1919. QueuePacket(app);
  1920. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1921. }
  1922. break;
  1923. }
  1924. case OP_RemoteCmdMsg: {
  1925. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RemoteCmdMsg", opcode, opcode);
  1926. if (app->size > 0) {
  1927. EQ2_CommandString remote(app->pBuffer, app->size);
  1928. LogWrite(PACKET__DEBUG, 1, "Packet", "RemoteCmdMsg Packet dump:");
  1929. #if EQDEBUG >= 9
  1930. DumpPacket(app);
  1931. #endif
  1932. commands.Process(remote.handler, &remote.command, this);
  1933. }
  1934. else //bad client, disconnect
  1935. Disconnect();
  1936. break;
  1937. }
  1938. case OP_CancelSpellCast: {
  1939. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CancelSpellCast", opcode, opcode);
  1940. current_zone->Interrupted(player, 0, 0, true);
  1941. SimpleMessage(CHANNEL_SPELLS_OTHER, "You stop casting.");
  1942. break;
  1943. }
  1944. case OP_UpdatePositionMsg: {
  1945. LogWrite(OPCODE__DEBUG, 7, "Opcode", "Opcode 0x%X (%i): OP_UpdatePositionMsg from %s", opcode, opcode, GetPlayer()->GetName());
  1946. int8 offset = 13;
  1947. if (app->pBuffer[0] == 0xFF)
  1948. offset += 2;
  1949. if (app->size > offset) {
  1950. if (player->IsCasting()) {
  1951. float distance = 0;
  1952. float x = player->GetX();
  1953. float y = player->GetY();
  1954. float z = player->GetZ();
  1955. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1956. distance = player->GetDistance(x, y, z, false);
  1957. if (distance > .5)
  1958. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1959. }
  1960. else
  1961. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1962. player_pos_changed = true;
  1963. GetPlayer()->changed = true;
  1964. GetPlayer()->info_changed = true;
  1965. GetPlayer()->vis_changed = true;
  1966. GetPlayer()->AddChangedZoneSpawn();
  1967. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1968. //DumpPacket(app);
  1969. }
  1970. break;
  1971. }
  1972. case OP_MailSendMessageMsg: {
  1973. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MailSendMessageMsg", opcode, opcode);
  1974. HandleSentMail(app);
  1975. break;
  1976. }
  1977. case OP_StopTrackingMsg: {
  1978. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopTrackingMsg", opcode, opcode);
  1979. player->GetZone()->RemovePlayerTracking(player, TRACKING_STOP);
  1980. break;
  1981. }
  1982. case OP_BeginTrackingMsg: {
  1983. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginTrackingMsg", opcode, opcode);
  1984. PacketStruct* packet = configReader.getStruct("WS_BeginTracking", GetVersion());
  1985. if (packet) {
  1986. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1987. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1988. Spawn* spawn = player->GetSpawnWithPlayerID(spawn_id);
  1989. if (spawn) {
  1990. AddWaypoint(spawn->GetName(), WAYPOINT_CATEGORY_TRACKING, spawn_id);
  1991. BeginWaypoint(spawn->GetName(), spawn->GetX(), spawn->GetY(), spawn->GetZ());
  1992. player->GetZone()->RemovePlayerTracking(player, TRACKING_CLOSE_WINDOW);
  1993. }
  1994. }
  1995. safe_delete(packet);
  1996. }
  1997. break;
  1998. }
  1999. case OP_BioUpdateMsg: {
  2000. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BioUpdateMsg", opcode, opcode);
  2001. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  2002. if (packet) {
  2003. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  2004. player->SetBiography(packet->getType_EQ2_16BitString_ByName("biography").data);
  2005. }
  2006. safe_delete(packet);
  2007. }
  2008. break;
  2009. }
  2010. case OP_RewardPackMsg: {
  2011. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RewardPackMsg", opcode, opcode);
  2012. /* 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
  2013. when we come across it (scatman) */
  2014. const char* name = app->GetOpcodeName();
  2015. if (name)
  2016. LogWrite(WORLD__DEBUG, 0, "World", "%s Received OP_RewardPackMsg %04i", name, app->GetRawOpcode());
  2017. else
  2018. LogWrite(WORLD__DEBUG, 0, "World", "Received OP_RewardPackMsg %04i", app->GetRawOpcode());
  2019. //DumpPacket(app);
  2020. PacketStruct* packet = configReader.getStruct("WS_RewardPackMsg", GetVersion());
  2021. if (packet) {
  2022. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  2023. string recruiter_name = packet->getType_EQ2_16BitString_ByName("recruiter_name").data;
  2024. /* Player has contacted a guild recruiter */
  2025. if (recruiter_name.length() > 0) {
  2026. Guild* guild = guild_list.GetGuild(packet->getType_int32_ByName("guild_id"));
  2027. Client* recruiter = zone_list.GetClientByCharName(recruiter_name);
  2028. if (recruiter && guild) {
  2029. Message(CHANNEL_GUILD_EVENT, "Contact request sent to %s of %s.", recruiter->GetPlayer()->GetName(), guild->GetName());
  2030. 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()));
  2031. recruiter->PlaySound("ui_guild_page");
  2032. }
  2033. }
  2034. /* New picture taken for guild recruiting */
  2035. else {
  2036. //DumpPacket(app->pBuffer, app->size);
  2037. int32 guild_id = 0;
  2038. int16 picture_data_size = 0;
  2039. unsigned char* recruiter_picture_data = 0;
  2040. memcpy(&guild_id, app->pBuffer + 4, sizeof(int32));
  2041. memcpy(&picture_data_size, app->pBuffer + 15, sizeof(int16));
  2042. Guild* guild = guild_list.GetGuild(guild_id);
  2043. if (guild) {
  2044. GuildMember* gm = guild->GetGuildMember(player);
  2045. if (gm) {
  2046. safe_delete_array(gm->recruiter_picture_data);
  2047. recruiter_picture_data = new unsigned char[picture_data_size];
  2048. for (int16 i = 0; i < picture_data_size; i++)
  2049. memcpy(recruiter_picture_data + i, app->pBuffer + 17 + i, 2);
  2050. gm->recruiter_picture_data = recruiter_picture_data;
  2051. gm->recruiter_picture_data_size = picture_data_size;
  2052. guild->SetMemberSaveNeeded(true);
  2053. }
  2054. }
  2055. }
  2056. }
  2057. safe_delete(packet);
  2058. }
  2059. break;
  2060. }
  2061. case OP_PetOptions: {
  2062. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PetOptions", opcode, opcode);
  2063. Spawn* target = player->GetTarget();
  2064. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  2065. if (packet && target && (target == player->GetPet() || target == player->GetCharmedPet() || target == player->GetDeityPet() || target == player->GetCosmeticPet())) {
  2066. bool change = false;
  2067. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  2068. string name = packet->getType_EQ2_16BitString_ByName("pet_name").data;
  2069. if (strlen(name.c_str()) != 0 && SetPetName(name.c_str())) {
  2070. target->SetName(name.c_str());
  2071. GetCurrentZone()->SendUpdateTitles(target);
  2072. change = true;
  2073. }
  2074. int8 pet_behavior = player->GetInfoStruct()->get_pet_behavior();
  2075. // Check protect self setting and update if needed
  2076. if (packet->getType_int8_ByName("protect_self") == 1) {
  2077. if ((pet_behavior & 2) == 0) {
  2078. player->GetInfoStruct()->set_pet_behavior(pet_behavior + 2);
  2079. change = true;
  2080. }
  2081. }
  2082. else {
  2083. if ((pet_behavior & 2) != 0) {
  2084. player->GetInfoStruct()->set_pet_behavior(pet_behavior - 2);
  2085. change = true;
  2086. }
  2087. }
  2088. // Check protect master setting and update if needed
  2089. if (packet->getType_int8_ByName("protect_master") == 1) {
  2090. if ((pet_behavior & 1) == 0) {
  2091. player->GetInfoStruct()->set_pet_behavior(pet_behavior + 1);
  2092. change = true;
  2093. }
  2094. }
  2095. else {
  2096. if ((pet_behavior & 1) != 0) {
  2097. player->GetInfoStruct()->set_pet_behavior(pet_behavior - 1);
  2098. change = true;
  2099. }
  2100. }
  2101. int8 pet_movement = player->GetInfoStruct()->get_pet_movement();
  2102. // Check stay/follow setting and update if needed
  2103. if (packet->getType_int8_ByName("stay_follow_toggle") == 1) {
  2104. if (pet_movement != 2) {
  2105. player->GetInfoStruct()->set_pet_movement(2);
  2106. change = true;
  2107. }
  2108. }
  2109. else {
  2110. if (pet_movement != 1) {
  2111. player->GetInfoStruct()->set_pet_movement(1);
  2112. change = true;
  2113. }
  2114. }
  2115. // Ranged/Melee settings are not implemented yet
  2116. if (change)
  2117. player->SetCharSheetChanged(true);
  2118. }
  2119. safe_delete(packet);
  2120. }
  2121. break;
  2122. }
  2123. case OP_RecipeBook: {
  2124. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RecipeBook", opcode, opcode);
  2125. SendRecipeList();
  2126. break;
  2127. }
  2128. case OP_BuyPlayerHouseMsg: {
  2129. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BuyPlayerHouseMsg", opcode, opcode);
  2130. //DumpPacket(app);
  2131. int64 bank_money = GetPlayer()->GetBankCoinsPlat();
  2132. PacketStruct* packet = configReader.getStruct("WS_BuyHouse", GetVersion());
  2133. if (packet) {
  2134. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  2135. int64 house_id = 0;
  2136. if (GetVersion() <= 561) {
  2137. house_id = packet->getType_int32_ByName("house_id");
  2138. }
  2139. else {
  2140. house_id = packet->getType_int64_ByName("house_id");
  2141. }
  2142. HouseZone* hz = world.GetHouseZone(house_id);
  2143. if (hz) {
  2144. bool got_bank_money = BankHasCoin(hz->cost_coin);
  2145. int8 disable_alignment_req = rule_manager.GetZoneRule(GetCurrentZoneID(), R_Player, DisableHouseAlignmentRequirement)->GetInt8();
  2146. std::vector<PlayerHouse*> houses = world.GetAllPlayerHouses(GetCharacterID());
  2147. if (houses.size() > 24)
  2148. {
  2149. SimpleMessage(CHANNEL_COLOR_YELLOW, "You already own 25 houses and may not own another.");
  2150. safe_delete(packet);
  2151. break;
  2152. }
  2153. if (disable_alignment_req && hz->alignment > 0 && hz->alignment != GetPlayer()->GetAlignment())
  2154. {
  2155. std::string req = "You must be of ";
  2156. if (hz->alignment == 1)
  2157. req.append("Good");
  2158. else
  2159. req.append("Evil");
  2160. req.append(" alignment to purchase this house");
  2161. SimpleMessage(CHANNEL_COLOR_YELLOW, req.c_str());
  2162. safe_delete(packet);
  2163. break;
  2164. }
  2165. ZoneChangeDetails zone_details;
  2166. int32 status_req = hz->cost_status;
  2167. int32 available_status = player->GetInfoStruct()->get_status_points();
  2168. if (status_req <= available_status && (!hz->cost_coin || (hz->cost_coin && player->RemoveCoins(hz->cost_coin))))
  2169. {
  2170. player->GetInfoStruct()->subtract_status_points(status_req);
  2171. if (zone_list.GetZoneByInstance(&zone_details, 0, hz->zone_id, true, true)) {
  2172. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800; // 604800 = 7 days
  2173. int64 unique_id = database.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, zone_details.instanceId, upkeep_due);
  2174. int32 db_id = database.AddCharacterInstance(GetPlayer()->GetCharacterID(), zone_details.instanceId, zone_details.zoneName, zone_details.instanceType, Timer::GetUnixTimeStamp(), 0, zone_details.defaultLockoutTime, zone_details.defaultReenterTime);
  2175. if (db_id > 0)
  2176. GetPlayer()->GetCharacterInstances()->AddInstance(db_id, zone_details.instanceId, 0, 0, zone_details.defaultLockoutTime, zone_details.defaultReenterTime, zoneID, zone_details.instanceType, zone_details.zoneName);
  2177. world.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, unique_id, zone_details.instanceId, upkeep_due, 0, 0, GetPlayer()->GetName());
  2178. //ClientPacketFunctions::SendHousingList(this);
  2179. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(unique_id);
  2180. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 561 ? house_id : this->GetPlayer()->GetID());
  2181. PlaySound("coin_cha_ching");
  2182. }
  2183. }
  2184. else if (status_req <= available_status && got_bank_money == 1) {
  2185. player->GetInfoStruct()->subtract_status_points(status_req);
  2186. bool bankwithdrawl = BankWithdrawalNoBanker(hz->cost_coin);
  2187. //this should NEVER happen since we check with got_bank_money, however adding it here should something go nutty.
  2188. if (bankwithdrawl == 0) {
  2189. PlaySound("buy_failed");
  2190. SimpleMessage(CHANNEL_COLOR_RED, "There was an error in bankwithdrawl function.");
  2191. safe_delete(packet);
  2192. break;
  2193. }
  2194. if (zone_list.GetZoneByInstance(&zone_details, 0, hz->zone_id, true, true)) {
  2195. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800; // 604800 = 7 days
  2196. int64 unique_id = database.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, zone_details.instanceId, upkeep_due);
  2197. int32 db_id = database.AddCharacterInstance(GetPlayer()->GetCharacterID(), zone_details.instanceId, zone_details.zoneName, zone_details.instanceType, Timer::GetUnixTimeStamp(), 0, zone_details.defaultLockoutTime, zone_details.defaultReenterTime);
  2198. if (db_id > 0)
  2199. GetPlayer()->GetCharacterInstances()->AddInstance(db_id, zone_details.instanceId, 0, 0, zone_details.defaultLockoutTime, zone_details.defaultReenterTime, zoneID, zone_details.instanceType, zone_details.zoneName);
  2200. world.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, unique_id, zone_details.instanceId, upkeep_due, 0, 0, GetPlayer()->GetName());
  2201. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(unique_id);
  2202. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 561 ? house_id : this->GetPlayer()->GetID());
  2203. PlaySound("coin_cha_ching");
  2204. }
  2205. }
  2206. else
  2207. {
  2208. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money to purchase the house.");
  2209. PlaySound("buy_failed");
  2210. }
  2211. }
  2212. }
  2213. }
  2214. safe_delete(packet);
  2215. break;
  2216. }
  2217. case OP_EnterHouseMsg: {
  2218. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EnterHouseMsg", opcode, opcode);
  2219. //DumpPacket(app);
  2220. PacketStruct* packet = configReader.getStruct("WS_EnterHouse", GetVersion());
  2221. if (packet) {
  2222. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  2223. PlayerHouse* ph = nullptr;
  2224. HouseZone* hz = nullptr;
  2225. int64 house_id = 0;
  2226. int32 spawn_index = 0;
  2227. if (GetVersion() <= 561) {
  2228. spawn_index = packet->getType_int32_ByName("house_id");
  2229. }
  2230. else {
  2231. house_id = packet->getType_int64_ByName("house_id");
  2232. }
  2233. ZoneChangeDetails zone_details;
  2234. if (GetHouseZoneServer(&zone_details, spawn_index, house_id)) {
  2235. Zone(&zone_details, (ZoneServer*)zone_details.zonePtr, true);
  2236. }
  2237. }
  2238. }
  2239. safe_delete(packet);
  2240. break;
  2241. }
  2242. case OP_PayHouseUpkeepMsg: {
  2243. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PayHouseUpkeepMsg", opcode, opcode);
  2244. PacketStruct* packet = configReader.getStruct("WS_PayUpkeep", GetVersion());
  2245. if (packet) {
  2246. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  2247. int64 house_id = 0;
  2248. if (GetVersion() <= 561) {
  2249. house_id = packet->getType_int32_ByName("house_id");
  2250. }
  2251. else {
  2252. house_id = packet->getType_int64_ByName("house_id");
  2253. }
  2254. HouseZone* hz = nullptr;
  2255. PlayerHouse* ph = world.GetPlayerHouse(this, GetVersion() <= 561 ? house_id : 0, GetVersion() > 561 ? house_id : 0, &hz);
  2256. if (ph)
  2257. {
  2258. if (!hz)
  2259. {
  2260. Message(CHANNEL_COLOR_YELLOW, "HouseZone ID %u does NOT exist!", ph->house_id);
  2261. safe_delete(packet);
  2262. break;
  2263. }
  2264. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800;
  2265. if (((sint64)ph->upkeep_due - (sint64)Timer::GetUnixTimeStamp()) > 0)
  2266. {
  2267. upkeep_due = ph->upkeep_due + 604800; // 604800 = 7 days
  2268. if (upkeep_due > (Timer::GetUnixTimeStamp() + 7257600)) // 84 days max upkeep to pay https://eq2.zam.com/wiki/Housing_%28EQ2%29#Upkeep
  2269. {
  2270. Message(CHANNEL_COLOR_YELLOW, "You cannot pay more than 3 months of upkeep.");
  2271. PlaySound("buy_failed");
  2272. safe_delete(packet);
  2273. break;
  2274. }
  2275. }
  2276. bool escrowChange = false;
  2277. int64 statusReq = hz->upkeep_status;
  2278. int64 tmpRecoverStatus = 0;
  2279. if (ph->escrow_status && statusReq >= ph->escrow_status)
  2280. {
  2281. escrowChange = true;
  2282. tmpRecoverStatus = ph->escrow_status;
  2283. statusReq -= ph->escrow_status;
  2284. ph->escrow_status = 0;
  2285. }
  2286. else if (ph->escrow_status && statusReq && statusReq <= ph->escrow_status)
  2287. {
  2288. escrowChange = true;
  2289. ph->escrow_status -= statusReq;
  2290. tmpRecoverStatus = statusReq;
  2291. statusReq = 0;
  2292. }
  2293. int64 coinReq = hz->upkeep_coin;
  2294. int64 tmpRecoverCoins = 0;
  2295. if (ph->escrow_coins && coinReq >= ph->escrow_coins) // more required to upkeep than in escrow, subtract what we have left
  2296. {
  2297. escrowChange = true;
  2298. tmpRecoverCoins = ph->escrow_coins;
  2299. coinReq -= ph->escrow_coins;
  2300. ph->escrow_coins = 0;
  2301. }
  2302. else if (ph->escrow_coins && coinReq && coinReq <= ph->escrow_coins)
  2303. {
  2304. escrowChange = true;
  2305. // more than enough in escrow, subtract and make our cost 0!
  2306. ph->escrow_coins -= coinReq;
  2307. tmpRecoverCoins = coinReq;
  2308. coinReq = 0;
  2309. }
  2310. int32 available_status_points = player->GetInfoStruct()->get_status_points();
  2311. if (!statusReq || (statusReq && statusReq <= available_status_points))
  2312. {
  2313. if (coinReq && player->RemoveCoins(coinReq))
  2314. coinReq = 0;
  2315. if (!coinReq && statusReq && player->GetInfoStruct()->subtract_status_points(statusReq))
  2316. statusReq = 0;
  2317. }
  2318. bool got_bank_money = BankHasCoin(hz->upkeep_coin);
  2319. if (!coinReq && !statusReq) // TODO: Need option to take from bank if player does not have enough coin on them
  2320. {
  2321. database.AddHistory(ph, GetPlayer()->GetName(), "Paid Upkeep", Timer::GetUnixTimeStamp(), hz->upkeep_coin, 0, 0);
  2322. if (escrowChange)
  2323. database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins, ph->escrow_status);
  2324. ph->upkeep_due = upkeep_due;
  2325. database.SetHouseUpkeepDue(GetCharacterID(), ph->house_id, ph->instance_id, ph->upkeep_due);
  2326. //ClientPacketFunctions::SendHousingList(this);
  2327. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 561 ? house_id : this->GetPlayer()->GetID());
  2328. PlaySound("coin_cha_ching");
  2329. }
  2330. else if (!statusReq && got_bank_money == 1) {
  2331. bool bankwithdrawl = BankWithdrawalNoBanker(hz->upkeep_coin);
  2332. //this should NEVER happen since we check with got_bank_money, however adding it here should something go nutty.
  2333. if (bankwithdrawl == 0) {
  2334. PlaySound("buy_failed");
  2335. SimpleMessage(CHANNEL_COLOR_RED, "There was an error in bankwithdrawl function.");
  2336. safe_delete(packet);
  2337. break;
  2338. }
  2339. database.AddHistory(ph, GetPlayer()->GetName(), "Paid Upkeep", Timer::GetUnixTimeStamp(), hz->upkeep_coin, 0, 0);
  2340. if (escrowChange)
  2341. database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins, ph->escrow_status);
  2342. ph->upkeep_due = upkeep_due;
  2343. database.SetHouseUpkeepDue(GetCharacterID(), ph->house_id, ph->instance_id, ph->upkeep_due);
  2344. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 561 ? house_id : this->GetPlayer()->GetID());
  2345. PlaySound("coin_cha_ching");
  2346. }
  2347. else
  2348. {
  2349. // recover the escrow we were going to use but could not spend due to lack of funds
  2350. if (tmpRecoverCoins)
  2351. ph->escrow_coins += tmpRecoverCoins;
  2352. if (tmpRecoverStatus)
  2353. ph->escrow_status += tmpRecoverStatus;
  2354. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money or status to pay for upkeep.");
  2355. PlaySound("buy_failed");
  2356. }
  2357. }
  2358. else
  2359. Message(CHANNEL_COLOR_YELLOW, "PlayerHouse ID %u does NOT exist!", house_id);
  2360. }
  2361. }
  2362. safe_delete(packet);
  2363. break;
  2364. }
  2365. case OP_ExitHouseMsg: {
  2366. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExitHouseMsg", opcode, opcode);
  2367. int32 instance_id = GetCurrentZone()->GetInstanceID();
  2368. if (instance_id > 0) {
  2369. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(instance_id);
  2370. if (ph) {
  2371. HouseZone* hz = world.GetHouseZone(ph->house_id);
  2372. if (hz) {
  2373. // determine if this is an instanced zone that already exists
  2374. ZoneChangeDetails zone_details;
  2375. bool foundZone = world.GetGroupManager()->IdentifyMemberInGroupOrRaid(&zone_details, this, hz->exit_zone_id);
  2376. if (foundZone) {
  2377. GetPlayer()->SetX(hz->exit_x);
  2378. GetPlayer()->SetY(hz->exit_y);
  2379. GetPlayer()->SetZ(hz->exit_z);
  2380. GetPlayer()->SetHeading(hz->exit_heading);
  2381. Zone(&zone_details, (ZoneServer*)zone_details.zonePtr, false, true);
  2382. }
  2383. else {
  2384. if (zone_list.GetZone(&zone_details, hz->exit_zone_id)) {
  2385. GetPlayer()->SetX(hz->exit_x);
  2386. GetPlayer()->SetY(hz->exit_y);
  2387. GetPlayer()->SetZ(hz->exit_z);
  2388. GetPlayer()->SetHeading(hz->exit_heading);
  2389. Zone(&zone_details, (ZoneServer*)zone_details.zonePtr, false);
  2390. }
  2391. else {
  2392. LogWrite(CCLIENT__ERROR, 0, "Client", "Failed to OP_ExitHouseMsg(exit_zone_id = %u) for Player %s.", hz->exit_zone_id, GetPlayer()->GetName());
  2393. }
  2394. }
  2395. }
  2396. }
  2397. }
  2398. break;
  2399. }
  2400. case OP_QuestJournalWaypointMsg: {
  2401. //DumpPacket(app);
  2402. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalWaypointMsg", opcode, opcode);
  2403. PacketStruct* packet = configReader.getStruct("WS_QuestJournalWaypoint", GetVersion());
  2404. if (packet) {
  2405. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  2406. if (GetVersion() <= 561) {
  2407. int32 quest_id = packet->getType_int32_ByName("quest_id");
  2408. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  2409. if (player->player_quests.count(quest_id) > 0 && player->player_quests[quest_id]) {
  2410. if (player->player_quests[quest_id]->GetTracked())
  2411. player->player_quests[quest_id]->SetTracked(false);
  2412. else
  2413. player->player_quests[quest_id]->SetTracked(true);
  2414. player->player_quests[quest_id]->SetSaveNeeded(true);
  2415. }
  2416. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  2417. }
  2418. else {
  2419. int32 quests = packet->getType_int32_ByName("num_quests");
  2420. if (quests > 100) // just picking a number higher than max allowed
  2421. {
  2422. LogWrite(CCLIENT__ERROR, 0, "Client", "num_quests = %u - quantity too high, aborting load.", quests);
  2423. break;
  2424. }
  2425. LogWrite(CCLIENT__DEBUG, 0, "Client", "num_quests = %u", quests);
  2426. for (int32 i = 0; i < quests; i++) {
  2427. int32 id = packet->getType_int32_ByName("quest_id_0", i);
  2428. if (id == 0)
  2429. continue;
  2430. LogWrite(CCLIENT__DEBUG, 5, "Client", "quest_id = %u", id);
  2431. bool tracked = packet->getType_int8_ByName("quest_tracked_0", i) == 1 ? true : false;
  2432. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  2433. if (player->player_quests.count(id) > 0 && player->player_quests[id]) {
  2434. player->player_quests[id]->SetTracked(tracked);
  2435. player->player_quests[id]->SetSaveNeeded(true);
  2436. }
  2437. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  2438. }
  2439. }
  2440. }
  2441. safe_delete(packet);
  2442. }
  2443. break;
  2444. }
  2445. case OP_PaperdollImage: {
  2446. /* PacketStruct* packet = configReader.getStruct("WS_PaperdollImage", version);
  2447. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  2448. //First check if this is a new image... delete an existing partial image if one exists
  2449. int8 packet_index = packet->getType_int8_ByName("packetIndex");
  2450. if (packet_index == 0) {
  2451. safe_delete_array(incoming_paperdoll.image_bytes);
  2452. incoming_paperdoll.last_received_packet_index = 0;
  2453. incoming_paperdoll.current_size_bytes = 0;
  2454. }
  2455. //return if this packet is not the one we are expecting...
  2456. else if (packet_index != incoming_paperdoll.last_received_packet_index + 1) {
  2457. safe_delete(packet);
  2458. break;
  2459. }
  2460. //Check how many packets we're supposed to be receiving for this/these images
  2461. incoming_paperdoll.image_num_packets = packet->getType_int8_ByName("totalNumPackets");
  2462. //Check the image type, if this is a new type in the same series of packets we have a new image
  2463. int8 img_type = packet->getType_int8_ByName("image_type");
  2464. if (packet_index != 0 && img_type != incoming_paperdoll.image_type) {
  2465. //We have a new image. Save the old data and clear before continuing
  2466. SavePlayerImages();
  2467. }
  2468. incoming_paperdoll.image_type = img_type;
  2469. //Get the size of the image data in this packet
  2470. sint64 image_size = packet->getType_int32_ByName("imageSize");
  2471. if (image_size <= 0 || image_size > 1048576) {
  2472. //If this packet is saying that the array is size <= 0 or > 1 MiB return out... it shouldn't be those sizes ever
  2473. safe_delete(packet);
  2474. break;
  2475. }
  2476. //Create a new array
  2477. int32 new_image_size = image_size;
  2478. uchar* new_image = new uchar[incoming_paperdoll.current_size_bytes + new_image_size];
  2479. if (incoming_paperdoll.image_bytes) {
  2480. memcpy(new_image, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  2481. safe_delete_array(incoming_paperdoll.image_bytes);
  2482. }
  2483. //variable i should be the index in the packet of the first PNG file byte
  2484. vector<DataStruct*>* d_structs = packet->getStructs();
  2485. vector<DataStruct*>::iterator itr;
  2486. int32 i = 0;
  2487. for (itr = d_structs->begin(); itr != d_structs->end(); itr++) {
  2488. DataStruct* ds = (*itr);
  2489. if (strcmp(ds->GetName(), "pngData_0") != 0)
  2490. i += ds->GetDataSizeInBytes();
  2491. else
  2492. break;
  2493. }
  2494. //Return if this packet is bad and we would read out of bounds
  2495. if (app->size - i < new_image_size) {
  2496. safe_delete(packet);
  2497. safe_delete_array(new_image);
  2498. break;
  2499. }
  2500. uchar* tmp = new_image + incoming_paperdoll.current_size_bytes;
  2501. memcpy(tmp, app->pBuffer + i, new_image_size);
  2502. incoming_paperdoll.current_size_bytes += new_image_size;
  2503. incoming_paperdoll.image_bytes = new_image;
  2504. //Check if this is the last packet we're expecting for this image. Create a final image if so
  2505. if (incoming_paperdoll.image_num_packets == 1 ||
  2506. incoming_paperdoll.last_received_packet_index + 2 == incoming_paperdoll.image_num_packets) {
  2507. SavePlayerImages();
  2508. }
  2509. incoming_paperdoll.last_received_packet_index = packet_index;
  2510. }
  2511. safe_delete(packet);
  2512. */
  2513. break;
  2514. }
  2515. case OP_ReadyForTakeOffMsg:
  2516. {
  2517. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyForTakeOffMsg", opcode, opcode);
  2518. int32 index = GetCurrentZone()->GetFlightPathIndex(GetPendingFlightPath());
  2519. if (GetPendingFlightPath() > 0) {
  2520. if (index != -1) {
  2521. PacketStruct* packet = configReader.getStruct("WS_ClearForTakeOff", GetVersion());
  2522. if (packet) {
  2523. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  2524. packet->setDataByName("path_id", index);
  2525. packet->setDataByName("speed", GetCurrentZone()->GetFlightPathSpeed(GetPendingFlightPath()));
  2526. QueuePacket(packet->serialize());
  2527. safe_delete(packet);
  2528. on_auto_mount = true;
  2529. }
  2530. }
  2531. else {
  2532. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but unable to get an index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2533. Message(CHANNEL_ERROR, "Unable to get index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2534. EndAutoMount();
  2535. }
  2536. SetPendingFlightPath(0);
  2537. }
  2538. else
  2539. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but there is no pending flight path...");
  2540. break;
  2541. }
  2542. case OP_EarlyLandingRequestMsg:
  2543. {
  2544. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EarlyLandingRequestMsg", opcode, opcode);
  2545. EndAutoMount();
  2546. break;
  2547. }
  2548. case OP_SubmitCharCust:
  2549. {
  2550. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SubmitCharCust", opcode, opcode);
  2551. PacketStruct* packet = configReader.getStruct("WS_SubmitCharCust", version);
  2552. if (packet && packet->LoadPacketData(app->pBuffer, app->size, GetVersion() <= 561 ? false : true)) {
  2553. int8 type = packet->getType_int8_ByName("type");
  2554. if (type == 0) {
  2555. /*if (player->custNPC) {
  2556. player->custNPCTarget->CustomizeAppearance(packet);
  2557. current_zone->SendSpawnChanges(player->custNPCTarget);
  2558. }
  2559. else {*/
  2560. player->CustomizeAppearance(packet);
  2561. current_zone->SendSpawnChanges(player);
  2562. //}
  2563. }
  2564. }
  2565. safe_delete(packet);
  2566. /*
  2567. if (player->custNPC) {
  2568. memcpy(&player->appearance, &player->SavedApp, sizeof(AppearanceData));
  2569. memcpy(&player->features, &player->SavedFeatures, sizeof(CharFeatures));
  2570. if (player->custNPCTarget->IsBot())
  2571. database.SaveBotAppearance((Bot*)player->custNPCTarget);
  2572. player->custNPC = false;
  2573. player->custNPCTarget = 0;
  2574. player->changed = true;
  2575. player->info_changed = true;
  2576. current_zone->SendSpawnChanges(player, this);
  2577. }*/
  2578. break;
  2579. }
  2580. default: {
  2581. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): Unknown in %s", opcode, opcode, __FILE__);
  2582. const char* name = app->GetOpcodeName();
  2583. if (name)
  2584. LogWrite(OPCODE__DEBUG, 1, "Opcode", "%s Received %04X (%i)", name, app->GetRawOpcode(), app->GetRawOpcode());
  2585. else
  2586. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Received %04X (%i)", app->GetRawOpcode(), app->GetRawOpcode());
  2587. // keeping this around for debugging purposes
  2588. //DumpPacket(app);
  2589. }
  2590. }
  2591. if (!eqs || !eqs->CheckActive()) {
  2592. return false;
  2593. }
  2594. return ret;
  2595. }
  2596. bool Client::HandleLootItem(Spawn* entity, Item* item, Spawn* target, bool overrideLootRestrictions) {
  2597. if (!item) {
  2598. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find item to loot!");
  2599. return false;
  2600. }
  2601. int32 conflictItemList = 0, conflictequipmentList = 0, conflictAppearanceEquipmentList = 0;
  2602. int16 lore_stack_count = 0;
  2603. Player* lootingPlayer = player;
  2604. Client* lootingClient = this;
  2605. if (target != nullptr && target != lootingPlayer && target->IsPlayer()) {
  2606. lootingPlayer = (Player*)target;
  2607. lootingClient = lootingPlayer->GetClient();
  2608. }
  2609. // needs to only be checked before expiration of loot restrictions
  2610. if (entity && !overrideLootRestrictions) {
  2611. std::vector<int32> raidGroups;
  2612. if (lootingPlayer && lootingPlayer->GetGroupMemberInfo())
  2613. world.GetGroupManager()->GetRaidGroups(lootingPlayer->GetGroupMemberInfo()->group_id, &raidGroups);
  2614. if (entity->GetLootGroupID() > 0 && std::find(raidGroups.begin(), raidGroups.end(), entity->GetLootGroupID()) == raidGroups.end() && (!lootingPlayer->GetGroupMemberInfo() || lootingPlayer->GetGroupMemberInfo()->group_id != entity->GetLootGroupID())) {
  2615. 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());
  2616. return false;
  2617. }
  2618. if (entity->GetLootMethod() != GroupLootMethod::METHOD_FFA) {
  2619. switch (entity->GetLootMethod()) {
  2620. case GroupLootMethod::METHOD_LEADER: {
  2621. bool inRaid = false;
  2622. bool isLeaderRaid = false;
  2623. if (GetPlayer()->GetGroupMemberInfo()) {
  2624. inRaid = world.GetGroupManager()->IsInRaidGroup(GetPlayer()->GetGroupMemberInfo()->group_id, GetPlayer()->GetGroupMemberInfo()->group_id, false);
  2625. isLeaderRaid = world.GetGroupManager()->IsInRaidGroup(GetPlayer()->GetGroupMemberInfo()->group_id, GetPlayer()->GetGroupMemberInfo()->group_id, true);
  2626. }
  2627. if (entity->GetLootGroupID() > 0 && (!GetPlayer()->GetGroupMemberInfo() || !lootingPlayer->GetGroupMemberInfo() || (inRaid && !isLeaderRaid) || ((std::find(raidGroups.begin(), raidGroups.end(), GetPlayer()->GetGroupMemberInfo()->group_id) == raidGroups.end()) && lootingPlayer->GetGroupMemberInfo()->group_id != entity->GetLootGroupID()) || !GetPlayer()->GetGroupMemberInfo()->leader)) {
  2628. 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);
  2629. return false;
  2630. }
  2631. break;
  2632. }
  2633. case GroupLootMethod::METHOD_LOTTO:
  2634. case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
  2635. if (entity->IsLootTimerRunning()) {
  2636. 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);
  2637. return false;
  2638. }
  2639. break;
  2640. }
  2641. }
  2642. }
  2643. }
  2644. if (((conflictItemList = lootingPlayer->item_list.CheckSlotConflict(item, true, true, &lore_stack_count)) == LORE ||
  2645. (conflictequipmentList = lootingPlayer->equipment_list.CheckSlotConflict(item, true, &lore_stack_count)) == LORE ||
  2646. (conflictAppearanceEquipmentList = lootingPlayer->appearance_equipment_list.CheckSlotConflict(item, true, &lore_stack_count)) == LORE) && !item->CheckFlag(STACK_LORE)) {
  2647. Message(CHANNEL_COLOR_RED, "You cannot loot %s due to lore conflict.", item->name.c_str());
  2648. return false;
  2649. }
  2650. else if (conflictItemList == STACK_LORE || conflictequipmentList == STACK_LORE || conflictAppearanceEquipmentList == STACK_LORE) {
  2651. Message(CHANNEL_COLOR_RED, "You cannot loot %s due to stack lore conflict.", item->name.c_str());
  2652. return false;
  2653. }
  2654. if (lootingPlayer->item_list.HasFreeSlot() || lootingPlayer->item_list.CanStack(item)) {
  2655. if (lootingPlayer->item_list.AssignItemToFreeSlot(item)) {
  2656. if (item->CheckFlag2(HEIRLOOM)) { // TODO: RAID Support
  2657. GroupMemberInfo* gmi = lootingClient->GetPlayer()->GetGroupMemberInfo();
  2658. if (gmi && gmi->group_id)
  2659. {
  2660. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  2661. if (group)
  2662. {
  2663. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  2664. deque<GroupMemberInfo*>* members = group->GetMembers();
  2665. if (members) {
  2666. for (int8 i = 0; i < members->size(); i++) {
  2667. Entity* member = members->at(i)->member;
  2668. if (!member)
  2669. continue;
  2670. if ((member->GetZone() != lootingClient->GetPlayer()->GetZone()))
  2671. continue;
  2672. if (member->IsPlayer()) {
  2673. item->grouped_char_ids.insert(std::make_pair(((Player*)member)->GetCharacterID(), true));
  2674. item->save_needed = true;
  2675. }
  2676. }
  2677. }
  2678. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  2679. }
  2680. }
  2681. }
  2682. int8 type = CHANNEL_LOOT;
  2683. if (entity) {
  2684. lootingClient->Message(type, "You loot %s from the corpse of %s", item->CreateItemLink(GetVersion()).c_str(), entity->GetName());
  2685. }
  2686. else {
  2687. lootingClient->Message(type, "You found a %s.", item->CreateItemLink(GetVersion()).c_str());
  2688. }
  2689. Guild* guild = lootingPlayer->GetGuild();
  2690. if (guild && item->details.tier >= ITEM_TAG_LEGENDARY) {
  2691. char adjective[32];
  2692. int8 type;
  2693. memset(adjective, 0, sizeof(adjective));
  2694. if (item->details.tier >= ITEM_TAG_MYTHICAL) {
  2695. strncpy(adjective, "Mythical", sizeof(adjective) - 1);
  2696. type = GUILD_EVENT_LOOTS_MYTHICAL_ITEM;
  2697. }
  2698. else if (item->details.tier >= ITEM_TAG_FABLED) {
  2699. strncpy(adjective, "Fabled", sizeof(adjective) - 1);
  2700. type = GUILD_EVENT_LOOTS_FABELED_ITEM;
  2701. }
  2702. else {
  2703. strncpy(adjective, "Legendary", sizeof(adjective) - 1);
  2704. type = GUILD_EVENT_LOOTS_LEGENDARY_ITEM;
  2705. }
  2706. guild->AddNewGuildEvent(type, "%s has looted the %s %s", Timer::GetUnixTimeStamp(), true, lootingPlayer->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2707. guild->SendMessageToGuild(type, "%s has looted the %s %s", lootingPlayer->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2708. }
  2709. if (item->GetItemScript() && lua_interface)
  2710. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, lootingPlayer);
  2711. lootingClient->CheckPlayerQuestsItemUpdate(item);
  2712. if (GetVersion() <= 561) {
  2713. EQ2Packet* outapp = lootingPlayer->SendInventoryUpdate(GetVersion());
  2714. if (outapp)
  2715. lootingClient->QueuePacket(outapp);
  2716. }
  2717. return true;
  2718. }
  2719. else
  2720. lootingClient->SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  2721. }
  2722. else
  2723. lootingClient->SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to loot item: Inventory is FULL.");
  2724. return false;
  2725. }
  2726. bool Client::HandleLootItemByID(Spawn* entity, int32 item_id, Spawn* target) {
  2727. if (!entity) {
  2728. return false;
  2729. }
  2730. Item* item = entity->LootItem(item_id);
  2731. bool success = false;
  2732. success = HandleLootItem(entity, item, target);
  2733. if (!success)
  2734. entity->AddLootItem(item);
  2735. return success;
  2736. }
  2737. void Client::HandleLootItemRequestPacket(EQApplicationPacket* app) {
  2738. PacketStruct* packet = configReader.getStruct("WS_LootItem", GetVersion());
  2739. if (packet) {
  2740. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  2741. int32 loot_id = packet->getType_int32_ByName("loot_id");
  2742. bool loot_all = (packet->getType_int8_ByName("loot_all") == 1);
  2743. int32 target_id = packet->getType_int32_ByName("target_id");
  2744. int8 button_clicked = packet->getType_int8_ByName("button_clicked");
  2745. Spawn* spawn = GetCurrentZone()->GetSpawnByID(loot_id);
  2746. if (!spawn) {
  2747. safe_delete(packet);
  2748. return;
  2749. }
  2750. Item* item = nullptr;
  2751. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  2752. if (items) {
  2753. int32 items_looted = 0;
  2754. int32 item_id = packet->getType_int32_ByName("item_id_0");
  2755. for (int32 i = 0; i < items->size(); i++) {
  2756. Item* master_item = items->at(i);
  2757. if (master_item && (loot_all || master_item->details.item_id == item_id)) {
  2758. item = new Item(master_item);
  2759. if (item) {
  2760. loot_all = HandleLootItem(0, item);
  2761. if (loot_all) {
  2762. player->RemovePendingLootItem(loot_id, item->details.item_id);
  2763. if (GetVersion() <= 561) {
  2764. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2765. if (outapp)
  2766. QueuePacket(outapp);
  2767. }
  2768. if (master_item->details.item_id == item_id) {
  2769. break;
  2770. }
  2771. }
  2772. }
  2773. if (!loot_all)
  2774. break;
  2775. }
  2776. }
  2777. if (((loot_all && !item_id) || (loot_all && item_id && items->size() == 1)) || items->size() < 1) {
  2778. CloseLoot(loot_id);
  2779. }
  2780. else {
  2781. vector<Item*>* items2 = player->GetPendingLootItems(loot_id);
  2782. SendLootResponsePacket(spawn->GetLootCoins(), items2, spawn, true);
  2783. safe_delete(items2);
  2784. }
  2785. safe_delete(items);
  2786. safe_delete(packet);
  2787. return;
  2788. }
  2789. spawn->LockLoot();
  2790. bool unlockedLoot = false;
  2791. if (spawn && !spawn->Alive() && spawn->IsNPC() && ((NPC*)spawn)->Brain()->CheckLootAllowed(player)) {
  2792. if (loot_all) {
  2793. switch (spawn->GetLootMethod()) {
  2794. case GroupLootMethod::METHOD_LOTTO: {
  2795. spawn->AddLottoItemRequest(0xFFFFFFFF, GetPlayer()->GetID());
  2796. break;
  2797. }
  2798. case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
  2799. spawn->AddNeedGreedItemRequest(0xFFFFFFFF, GetPlayer()->GetID(), true);
  2800. }
  2801. default: {
  2802. if (!unlockedLoot) {
  2803. spawn->UnlockLoot();
  2804. unlockedLoot = true;
  2805. }
  2806. int32 item_id = 0;
  2807. while (loot_all && ((item_id = spawn->GetLootItemID()) > 0)) {
  2808. loot_all = HandleLootItemByID(spawn, item_id, GetPlayer());
  2809. }
  2810. break;
  2811. }
  2812. }
  2813. spawn->UnlockLoot();
  2814. if (spawn->GetLootMethod() == GroupLootMethod::METHOD_LOTTO) {
  2815. CloseLoot(loot_id);
  2816. }
  2817. }
  2818. else {
  2819. int8 item_count = packet->getType_int8_ByName("item_count");
  2820. for (int8 cur = 0; cur < item_count; cur++) {
  2821. char item_field_name[64];
  2822. snprintf(item_field_name, 64, "item_id_%u", cur);
  2823. int32 item_id = packet->getType_int32_ByName(item_field_name);
  2824. Spawn* target = this->GetPlayer();
  2825. if (target_id != 0xFFFFFFFF && GetPlayer()->GetGroupMemberInfo()) {
  2826. Spawn* destTarget = GetPlayer()->GetSpawnWithPlayerID(target_id);
  2827. std::vector<int32> raidGroups;
  2828. if (destTarget && destTarget->IsEntity() && ((Entity*)destTarget)->GetGroupMemberInfo())
  2829. world.GetGroupManager()->GetRaidGroups(((Entity*)destTarget)->GetGroupMemberInfo()->group_id, &raidGroups);
  2830. if (destTarget && (!destTarget->IsPlayer() || (std::find(raidGroups.begin(), raidGroups.end(), GetPlayer()->GetGroupMemberInfo()->group_id) == raidGroups.end() && !world.GetGroupManager()->IsInGroup(GetPlayer()->GetGroupMemberInfo()->group_id, ((Player*)destTarget))))) {
  2831. SimpleMessage(CHANNEL_COMMAND_TEXT, "HACKS!!");
  2832. safe_delete(packet);
  2833. spawn->UnlockLoot();
  2834. return;
  2835. }
  2836. target = destTarget;
  2837. }
  2838. bool breakLoopAllLooted = false;
  2839. switch (spawn->GetLootMethod()) {
  2840. case GroupLootMethod::METHOD_LOTTO: {
  2841. spawn->AddLottoItemRequest(item_id, GetPlayer()->GetID());
  2842. break;
  2843. }
  2844. case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
  2845. if (button_clicked == 3) { // decline
  2846. break;
  2847. }
  2848. if (GetVersion() <= 561) {
  2849. button_clicked = 1; // selecting is need
  2850. }
  2851. spawn->AddNeedGreedItemRequest(item_id, GetPlayer()->GetID(), (button_clicked == 1));
  2852. break;
  2853. }
  2854. default: {
  2855. if (!unlockedLoot) {
  2856. spawn->UnlockLoot();
  2857. unlockedLoot = true;
  2858. }
  2859. if (!loot_all) {
  2860. HandleLootItemByID(spawn, item_id, target);
  2861. }
  2862. else {
  2863. while (loot_all && ((item_id = spawn->GetLootItemID()) > 0)) {
  2864. loot_all = HandleLootItemByID(spawn, item_id, target);
  2865. }
  2866. breakLoopAllLooted = true;
  2867. }
  2868. break;
  2869. }
  2870. }
  2871. if (breakLoopAllLooted) {
  2872. break;
  2873. }
  2874. }
  2875. if (!unlockedLoot) {
  2876. spawn->UnlockLoot();
  2877. }
  2878. if (spawn->GetLootMethod() == GroupLootMethod::METHOD_LOTTO ||
  2879. (spawn->GetLootMethod() == GroupLootMethod::METHOD_NEED_BEFORE_GREED && item_count >= spawn->GetLootCount())) {
  2880. CloseLoot(loot_id);
  2881. }
  2882. }
  2883. if (GetVersion() > 561) {
  2884. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2885. if (outapp)
  2886. QueuePacket(outapp);
  2887. }
  2888. if (spawn->GetLootMethod() != GroupLootMethod::METHOD_LOTTO && spawn->GetLootMethod() != GroupLootMethod::METHOD_NEED_BEFORE_GREED) {
  2889. LootSpawnRequest(spawn);
  2890. }
  2891. else {
  2892. spawn->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
  2893. }
  2894. if (!spawn->HasLoot()) {
  2895. CloseLoot(loot_id);
  2896. if (spawn->IsNPC())
  2897. GetCurrentZone()->RemoveDeadSpawn(spawn);
  2898. }
  2899. }
  2900. else {
  2901. spawn->UnlockLoot();
  2902. if (!spawn) {
  2903. LogWrite(WORLD__ERROR, 0, "World", "Unknown id of %u when looting!", loot_id);
  2904. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn to loot!");
  2905. }
  2906. else
  2907. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not unable to loot that at this time.");
  2908. }
  2909. }
  2910. safe_delete(packet);
  2911. }
  2912. }
  2913. void Client::HandleSkillInfoRequest(EQApplicationPacket* app) {
  2914. PacketStruct* request = 0;
  2915. // cout << "Request: \n";
  2916. // DumpPacket(app);
  2917. switch (app->pBuffer[0]) {
  2918. case 0: { //items
  2919. request = configReader.getStruct("WS_SkillInfoItemRequest", GetVersion());
  2920. if (request) {
  2921. if (request->LoadPacketData(app->pBuffer, app->size)) {
  2922. Item* item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(request->getType_int32_ByName("unique_id"));
  2923. if (!item)
  2924. item = GetPlayer()->item_list.GetItemFromUniqueID(request->getType_int32_ByName("unique_id"), true);
  2925. if (item) {
  2926. PacketStruct* response = configReader.getStruct("WS_SkillInfoItemResponse", GetVersion());
  2927. if (response) {
  2928. response->setDataByName("request_type", request->getType_int32_ByName("request_type"));
  2929. response->setDataByName("unique_id", request->getType_int32_ByName("unique_id"));
  2930. response->setSmallStringByName("name", item->name.c_str());
  2931. EQ2Packet* app2 = response->serialize();
  2932. //DumpPacket(app2);
  2933. QueuePacket(app2);
  2934. safe_delete(response);
  2935. }
  2936. }
  2937. }
  2938. safe_delete(request);
  2939. }
  2940. break;
  2941. }
  2942. case 2: {//spells
  2943. request = configReader.getStruct("WS_SkillInfoSpellRequest", GetVersion());
  2944. if (request) {
  2945. if (request->LoadPacketData(app->pBuffer, app->size)) {
  2946. int32 id = request->getType_int32_ByName("id");
  2947. int8 tier = request->getType_int32_ByName("unique_id"); //on live this is really unique_id, but I'm going to make it tier instead :)
  2948. Spell* spell = master_spell_list.GetSpell(id, tier);
  2949. PacketStruct* response = configReader.getStruct("WS_SkillInfoResponse", GetVersion());
  2950. if (response) {
  2951. response->setDataByName("request_type", 2);
  2952. response->setDataByName("unique_id", tier);
  2953. response->setDataByName("id", id);
  2954. if (spell)
  2955. response->setSmallStringByName("name", spell->GetName());
  2956. else
  2957. response->setSmallStringByName("name", "Unknown Spell");
  2958. EQ2Packet* app2 = response->serialize();
  2959. // DumpPacket(app2);
  2960. QueuePacket(app2);
  2961. safe_delete(response);
  2962. }
  2963. }
  2964. safe_delete(request);
  2965. }
  2966. break;
  2967. }
  2968. default: {
  2969. LogWrite(WORLD__ERROR, 0, "World", "Unknown SkillInfoRequest type of %i", (int)app->pBuffer[0]);
  2970. }
  2971. }
  2972. safe_delete(request);
  2973. }
  2974. void Client::HandleExamineInfoRequest(EQApplicationPacket* app) {
  2975. PacketStruct* request = 0;
  2976. if (!app || app->size == 0)
  2977. return;
  2978. //LogWrite(CCLIENT__DEBUG, 0, "Client", "Request2:");
  2979. int8 type = app->pBuffer[0];
  2980. //DumpPacket(app->pBuffer,app->size);
  2981. //283: item: 0, effect: 1, recipe: 2, spell: 3
  2982. if (version <= 373) {
  2983. if (type == 1)
  2984. type = 4;
  2985. else if (type == 2)
  2986. type = 5;
  2987. }
  2988. if (type == 3) {
  2989. Spell* spell = 0;
  2990. bool trait_display;
  2991. request = configReader.getStruct((GetVersion() <= 373) ? "WS_ExamineInfoRequest" : "WS_ExamineInfoRequestMsg", GetVersion());
  2992. if (!request) {
  2993. return;
  2994. }
  2995. if (!request->LoadPacketData(app->pBuffer, app->size)) {
  2996. safe_delete(request);
  2997. return;
  2998. }
  2999. int32 id = request->getType_int32_ByName("id");
  3000. int32 tier = request->getType_int32_ByName("tier");
  3001. int32 trait_tier = request->getType_int32_ByName("unknown_id");
  3002. if (GetVersion() > 373 && GetVersion() <= 561) {
  3003. trait_tier = request->getType_int32_ByName("unique_id");
  3004. }
  3005. bool display = true;
  3006. if (version <= 373 && request->getType_int8_ByName("display") == 1) // this is really requesting a partial packet
  3007. display = false;
  3008. else if (version <= 561)
  3009. display = request->getType_int8_ByName("display");
  3010. else if (version > 561)
  3011. display = false; // clients default is false otherwise it pops up a window when hovering over the knowledge book abilities
  3012. 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);
  3013. if (trait_tier != 0xFFFFFFFF) {
  3014. spell = master_spell_list.GetSpell(id, trait_tier);
  3015. if (!spell) {
  3016. spell = master_spell_list.GetSpell(id, trait_tier + 1);
  3017. }
  3018. trait_display = true;
  3019. }
  3020. else {
  3021. spell = master_spell_list.GetSpell(id, tier);
  3022. trait_display = false;
  3023. }
  3024. // if we can't find it on the master spell list, see if it is a custom spell
  3025. if (!spell)
  3026. {
  3027. lua_interface->FindCustomSpellLock();
  3028. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  3029. if (tmpSpell)
  3030. spell = tmpSpell->spell;
  3031. lua_interface->FindCustomSpellUnlock();
  3032. }
  3033. if (!spell) { // fix ui timeout for classic, isle of refuge, dof, kos clients
  3034. int8 playerTier = GetPlayer()->GetSpellTier(id);
  3035. spell = master_spell_list.GetSpell(id, playerTier);
  3036. 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);
  3037. }
  3038. if (spell && !CountSentSpell(spell->GetSpellID(), spell->GetSpellTier())) {
  3039. if (!spell->IsCopiedSpell())
  3040. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  3041. EQ2Packet* app = spell->SerializeSpell(this, display, trait_display);
  3042. //DumpPacket(app);
  3043. QueuePacket(app);
  3044. }
  3045. else if (spell && GetVersion() <= 561 && CountSentSpell(spell->GetSpellID(), spell->GetSpellTier())) {
  3046. EQ2Packet* app = spell->SerializeSpell(this, display, trait_display, GetVersion() <= 561 ? true : false);
  3047. //DumpPacket(app);
  3048. QueuePacket(app);
  3049. }
  3050. else {
  3051. 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);
  3052. }
  3053. }
  3054. else if (type == 0) {
  3055. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  3056. if (!request) {
  3057. return;
  3058. }
  3059. if (!request->LoadPacketData(app->pBuffer, app->size)) {
  3060. safe_delete(request);
  3061. return;
  3062. }
  3063. int32 id = request->getType_int32_ByName("id");
  3064. Item* item = 0;
  3065. // translate from unique id to spawn id for houses
  3066. Spawn* spawn = this->GetCurrentZone()->GetSpawnFromUniqueItemID(id);
  3067. bool wasSpawn = false;
  3068. if (spawn)
  3069. {
  3070. item = master_item_list.GetItem(spawn->GetPickupItemID());
  3071. if (item)
  3072. {
  3073. wasSpawn = true;
  3074. item = new Item(item);
  3075. item->details.unique_id = spawn->GetPickupUniqueItemID();
  3076. }
  3077. }
  3078. if (!item)
  3079. item = GetPlayer()->item_list.GetItemFromUniqueID(id, true);
  3080. if (!item)
  3081. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(id);
  3082. if (!item)
  3083. item = GetPlayer()->GetAppearanceEquipmentList()->GetItemFromUniqueID(id);
  3084. if (!item)
  3085. item = master_item_list.GetItem(id);
  3086. if (item) {// && sent_item_details.count(id) == 0){
  3087. MItemDetails.writelock(__FUNCTION__, __LINE__);
  3088. sent_item_details[id] = true;
  3089. MItemDetails.releasewritelock(__FUNCTION__, __LINE__);
  3090. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  3091. QueuePacket(app);
  3092. if (wasSpawn)
  3093. delete item;
  3094. }
  3095. else {
  3096. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  3097. DumpPacket(app);
  3098. }
  3099. }
  3100. else if (type == 1) {
  3101. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  3102. if (!request) {
  3103. return;
  3104. }
  3105. if (!request->LoadPacketData(app->pBuffer, app->size)) {
  3106. safe_delete(request);
  3107. return;
  3108. }
  3109. int32 id = request->getType_int32_ByName("id");
  3110. int32 unique_id = request->getType_int32_ByName("unique_id");
  3111. Item* item = GetPlayer()->item_list.GetItemFromUniqueID(unique_id, true);
  3112. if (!item)
  3113. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(unique_id);
  3114. if (!item)
  3115. item = GetPlayer()->GetAppearanceEquipmentList()->GetItemFromUniqueID(unique_id);
  3116. if (!item)
  3117. item = master_item_list.GetItem(id);
  3118. if (item) {
  3119. MItemDetails.writelock(__FUNCTION__, __LINE__);
  3120. sent_item_details[id] = true;
  3121. MItemDetails.releasewritelock(__FUNCTION__, __LINE__);
  3122. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  3123. QueuePacket(app);
  3124. }
  3125. else {
  3126. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  3127. DumpPacket(app);
  3128. }
  3129. }
  3130. else if (type == 2) {
  3131. request = configReader.getStruct("WS_ExamineInfoItemLinkRequest", GetVersion());
  3132. if (!request) {
  3133. return;
  3134. }
  3135. if (!request->LoadPacketData(app->pBuffer, app->size)) {
  3136. safe_delete(request);
  3137. return;
  3138. }
  3139. int32 id = request->getType_int32_ByName("item_id");
  3140. LogWrite(CCLIENT__DEBUG, 5, "Client", "Client::HandleExamineInfoRequest from %s: Found Type: (%i) Item ID: (%u)", GetPlayer()->GetName(), type, id);
  3141. //int32 unknown_0 = request->getType_int32_ByName("unknown",0);
  3142. //int32 unknown_1 = request->getType_int32_ByName("unknown",1);
  3143. //int8 unknown2 = request->getType_int8_ByName("unknown2");
  3144. //int32 unique_id = request->getType_int32_ByName("unique_id");
  3145. //int16 unknown5 = request->getType_sint16_ByName("unknown5");
  3146. //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);
  3147. Item* item = master_item_list.GetItem(id);
  3148. if (item) {
  3149. //only display popup for non merchant links
  3150. EQ2Packet* app = item->serialize(GetVersion(), (request->getType_int8_ByName("show_popup") != 0), GetPlayer(), true, 0, 0, GetVersion() > 561 ? true : false);
  3151. QueuePacket(app);
  3152. }
  3153. else {
  3154. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  3155. DumpPacket(app);
  3156. }
  3157. }
  3158. else if (type == 4) { //spell effect
  3159. request = configReader.getStruct("WS_ExamineSpellEffectRequest", GetVersion());
  3160. if (!request) {
  3161. return;
  3162. }
  3163. if (!request->LoadPacketData(app->pBuffer, app->size)) {
  3164. safe_delete(request);
  3165. return;
  3166. }
  3167. int32 id = request->getType_int32_ByName("id");
  3168. int16 display = request->getType_int8_ByName("partial_info");
  3169. SpellEffects* effect = player->GetSpellEffect(id);
  3170. //printf("Type: (%i) Unknown5: (%i) Item ID: (%u)\n",type,unknown5,id);
  3171. if (effect) {
  3172. LogWrite(CCLIENT__DEBUG, 5, "Client", "Client::HandleExamineInfoRequest from %s: Found Type: (%i) Item ID: (%u)", GetPlayer()->GetName(), type, id);
  3173. int8 tier = effect->tier;
  3174. Spell* spell = master_spell_list.GetSpell(id, tier);
  3175. // if we can't find it on the master spell list, see if it is a custom spell
  3176. if (!spell)
  3177. {
  3178. lua_interface->FindCustomSpellLock();
  3179. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  3180. EQ2Packet* pack = 0;
  3181. if (tmpSpell)
  3182. spell = tmpSpell->spell;
  3183. lua_interface->FindCustomSpellUnlock();
  3184. }
  3185. if (spell && (version <= 561 || !CountSentSpell(id, tier))) { // fix DoF and KoS clients UI Timeout
  3186. if (!spell->IsCopiedSpell())
  3187. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  3188. int8 type = 0;
  3189. if (version <= 373)
  3190. type = 1;
  3191. EQ2Packet* app = spell->SerializeSpecialSpell(this, false, type, 0x81);
  3192. //DumpPacket(app);
  3193. QueuePacket(app);
  3194. }
  3195. }
  3196. else {
  3197. LogWrite(CCLIENT__ERROR, 0, "Client", "Client::HandleExamineInfoRequest from %s: Cannot Find Type: (%i) Item ID: (%u)", GetPlayer()->GetName(), type, id);
  3198. }
  3199. }
  3200. else if (type == 5) { // recipe info
  3201. request = configReader.getStruct((GetVersion() <= 373) ? "WS_ExamineInfoRequest" : "WS_ExamineInfoRequestMsg", GetVersion());
  3202. if (!request)
  3203. return;
  3204. if (!request->LoadPacketData(app->pBuffer, app->size)) {
  3205. safe_delete(request);
  3206. return;
  3207. }
  3208. int32 id = 0;
  3209. if (GetVersion() < 546) {
  3210. id = request->getType_int32_ByName("id");
  3211. }
  3212. else if (GetVersion() <= 561) {
  3213. id = request->getType_int32_ByName("unique_id");
  3214. }
  3215. else {
  3216. id = request->getType_int32_ByName("unknown_id");
  3217. }
  3218. Recipe* recipe = master_recipe_list.GetRecipe(id);
  3219. if (recipe) {
  3220. EQ2Packet* app = recipe->SerializeRecipe(this, recipe, false, GetItemPacketType(GetVersion()), 0x02);
  3221. //DumpPacket(app);
  3222. QueuePacket(app);
  3223. }
  3224. }
  3225. else if (type == 6) { // AA spell info
  3226. Spell* spell = 0;
  3227. //Spell* spell2 = 0;
  3228. //AltAdvanceData* data = 0;
  3229. request = configReader.getStruct((GetVersion() <= 373) ? "WS_ExamineInfoRequest" : "WS_ExamineInfoRequestMsg", GetVersion());
  3230. if (!request)
  3231. return;
  3232. if (!request->LoadPacketData(app->pBuffer, app->size)) {
  3233. safe_delete(request);
  3234. return;
  3235. }
  3236. int32 id = request->getType_int32_ByName("id");
  3237. int32 tier = GetPlayer()->GetSpellTier(id);
  3238. LogWrite(WORLD__INFO, 0, "World", "Examine Info Request->Unique ID: %u Tier: %u ", id, tier);
  3239. //data = master_aa_list.GetAltAdvancement(id);
  3240. //LogWrite(WORLD__INFO, 0, "World", "SOE Spell CRC: %u", data->spell_crc);
  3241. //spell = master_spell_list.GetSpellByCRC(data->spell_crc);
  3242. spell = master_spell_list.GetSpell(id, tier);
  3243. if (!spell)
  3244. spell = master_spell_list.GetSpell(id, 1);
  3245. if (!spell)
  3246. {
  3247. lua_interface->FindCustomSpellLock();
  3248. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  3249. if (tmpSpell)
  3250. spell = tmpSpell->spell;
  3251. lua_interface->FindCustomSpellUnlock();
  3252. }
  3253. if (!spell)
  3254. {
  3255. LogWrite(CCLIENT__ERROR, 0, "Client", "WORLD", "Client::HandleExamineInfoRequest from %s: FAILED Examine Info Request-> Spell ID: %u, tier: %i", GetPlayer()->GetName(), id, tier);
  3256. return;
  3257. }
  3258. //if (spell && sent_spell_details.count(spell->GetSpellID()) == 0) {
  3259. if (!spell->IsCopiedSpell())
  3260. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  3261. // EQ2Packet* app = spell->SerializeAASpell(this,tier, data, false, GetItemPacketType(GetVersion()), 0x04);
  3262. LogWrite(WORLD__INFO, 0, "WORLD", "Examine Info Request-> Spell ID: %u", spell->GetSpellID());
  3263. if (GetVersion() > 561) {
  3264. EQ2Packet* app = master_spell_list.GetAASpellPacket(id, tier, this, false, 0x4F);//0x45 change version to match client
  3265. /////////////////////////////////////////GetAASpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type) {
  3266. //DumpPacket(app);
  3267. QueuePacket(app);
  3268. }
  3269. //}
  3270. }
  3271. else {
  3272. LogWrite(CCLIENT__ERROR, 0, "World", "Client::HandleExamineInfoRequest from %s: Unknown examine request: %i", GetPlayer()->GetName(), (int)type);
  3273. DumpPacket(app);
  3274. }
  3275. safe_delete(request);
  3276. }
  3277. void Client::HandleQuickbarUpdateRequest(EQApplicationPacket* app) {
  3278. PacketStruct* request = configReader.getStruct("WS_QuickBarUpdateRequest", GetVersion());
  3279. if (request) {
  3280. if (request->LoadPacketData(app->pBuffer, app->size)) {
  3281. int32 id = request->getType_int32_ByName("id");
  3282. int32 bar = request->getType_int32_ByName("hotbar_number");
  3283. int32 slot = request->getType_int32_ByName("hotkey_slot");
  3284. int32 type = request->getType_int32_ByName("type");
  3285. int8 tier = request->getType_int32_ByName("unique_id");
  3286. EQ2_16BitString text = request->getType_EQ2_16BitString_ByName("text");
  3287. Spell* spell = 0;
  3288. if (type == 0xFFFFFFFF)
  3289. GetPlayer()->RemoveQuickbarItem(bar, slot);
  3290. else {
  3291. if (type == QUICKBAR_NORMAL)
  3292. spell = master_spell_list.GetSpell(id, tier);
  3293. if (spell)
  3294. GetPlayer()->AddQuickbarItem(bar, slot, type, spell->GetSpellIcon(), spell->GetSpellIconBackdrop(), id, tier, 0, text.data.c_str());
  3295. else
  3296. GetPlayer()->AddQuickbarItem(bar, slot, type, 0, 0, id, 0, 0, text.data.c_str());
  3297. }
  3298. }
  3299. safe_delete(request);
  3300. }
  3301. }
  3302. bool Client::Process(bool zone_process) {
  3303. bool ret = true;
  3304. // EQS can become null if player is linkdead, we want to always be able to process the camp/linkdead timers when active
  3305. if ((camp_timer && camp_timer->Check()) || (linkdead_timer && linkdead_timer->Check())) {
  3306. ResetSendMail();
  3307. if (getConnection())
  3308. getConnection()->SendDisconnect(false);
  3309. safe_delete(camp_timer);
  3310. if (linkdead_timer) {
  3311. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player %s triggered linkdead timer, disconnecting", GetPlayer()->GetName());
  3312. // we remove the linkdead status and force a camp out immediately
  3313. if ((GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_LINKDEAD) > 0) {
  3314. GetPlayer()->SetActivityStatus(GetPlayer()->GetActivityStatus() - ACTIVITY_STATUS_LINKDEAD);
  3315. }
  3316. if ((GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0) {
  3317. GetPlayer()->SetActivityStatus(GetPlayer()->GetActivityStatus() + ACTIVITY_STATUS_CAMPING);
  3318. }
  3319. }
  3320. safe_delete(linkdead_timer);
  3321. ret = false;
  3322. }
  3323. if (client_zoning_details_set) {
  3324. if (!zoning_details.zoningPastAuth && (zoning_details.authDispatchedTime + 5) <= Timer::GetUnixTimeStamp()) {
  3325. zoning_details.zoningPastAuth = true; // don't repeat
  3326. world.ClientAuthApproval(0, std::string(player->GetName()), GetAccountID(), zoning_details.zoneName, zoning_details.zoneId, zoning_details.instanceId, false);
  3327. }
  3328. }
  3329. if (!eqs) {
  3330. return false;
  3331. }
  3332. if ((connected_to_zone && !zone_process) || (!connected_to_zone && zone_process)) {
  3333. return true;
  3334. }
  3335. switch (new_client_login) {
  3336. case NewLoginState::LOGIN_SEND: {
  3337. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendLoginInfo to new client...");
  3338. SendLoginInfo();
  3339. new_client_login = NewLoginState::LOGIN_NONE;
  3340. break;
  3341. }
  3342. case NewLoginState::LOGIN_INITIAL_LOAD: {
  3343. bool isDBActive = database.IsActiveQuery(GetCharacterID());
  3344. // wait for starting skills/spells to load and reload from DB.
  3345. if (!isDBActive) {
  3346. if (GetPlayer()->GetInfoStruct()->get_reload_player_spells()) {
  3347. database.LoadCharacterSpells(GetCharacterID(), GetPlayer());
  3348. GetPlayer()->GetInfoStruct()->set_reload_player_spells(0);
  3349. }
  3350. new_client_login = NewLoginState::LOGIN_SEND;
  3351. }
  3352. break;
  3353. }
  3354. case NewLoginState::LOGIN_ALLOWED: {
  3355. int32 count = 0;
  3356. if (!GetPlayer()->IsReturningFromLD())
  3357. {
  3358. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Skills for player '%s'...", player->GetName());
  3359. count = database.LoadCharacterSkills(GetCharacterID(), player);
  3360. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Spells for player '%s'...", player->GetName());
  3361. count = database.LoadCharacterSpells(GetCharacterID(), player);
  3362. }
  3363. else
  3364. {
  3365. LogWrite(CCLIENT__INFO, 0, "Client", "Player is returning from linkdead status (Player does not need reload) thus skipping database loading for '%s'...", player->GetName());
  3366. }
  3367. // get the latest character starting skills / spells, may have been updated after character creation
  3368. if (GetPlayer()->GetInfoStruct()->get_first_world_login()) {
  3369. world.SyncCharacterAbilities(this);
  3370. Query query;
  3371. query.AddQueryAsync(GetCharacterID(), &database, Q_UPDATE, "UPDATE characters set first_world_login = 0 where id=%u", GetCharacterID());
  3372. GetPlayer()->GetInfoStruct()->set_first_world_login(0);
  3373. }
  3374. new_client_login = NewLoginState::LOGIN_INITIAL_LOAD;
  3375. break;
  3376. }
  3377. case NewLoginState::LOGIN_DELAYED: {
  3378. if (!delay_msg_timer.Enabled() || delay_msg_timer.Check()) {
  3379. LogWrite(CCLIENT__INFO, 0, "Client", "Wait for zone %s to load for new client %s...", GetCurrentZone()->GetZoneName(), GetPlayer()->GetName());
  3380. delay_msg_timer.Start(1000, true);
  3381. }
  3382. if (!GetCurrentZone()->IsLoading()) {
  3383. new_client_login = NewLoginState::LOGIN_ALLOWED;
  3384. }
  3385. return true;
  3386. break;
  3387. }
  3388. }
  3389. delay_msg_timer.Disable();
  3390. sockaddr_in to;
  3391. memset((char*)&to, 0, sizeof(to));
  3392. to.sin_family = AF_INET;
  3393. to.sin_port = port;
  3394. to.sin_addr.s_addr = ip;
  3395. /************ Get all packets from packet manager out queue and process them ************/
  3396. EQApplicationPacket* app = 0;
  3397. if (eqs && !eqs->CheckActive()) {
  3398. num_active_failures++;
  3399. LogWrite(CCLIENT__DEBUG, 7, "Client", "%s, num_active_failures = %i", __FUNCTION__, num_active_failures);
  3400. if (num_active_failures > 100) {
  3401. return false;
  3402. }
  3403. return true;
  3404. }
  3405. while (ret && eqs && (app = eqs->PopPacket())) {
  3406. ret = HandlePacket(app);
  3407. LogWrite(CCLIENT__DEBUG, 5, "Client", "Func: %s, Line: %i, Opcode: '%s'", __FUNCTION__, __LINE__, app->GetOpcodeName());
  3408. delete app;
  3409. }
  3410. if (GetCurrentZone() && !GetCurrentZone()->IsLoading() && GetCurrentZone()->GetSpawnByID(GetPlayer()->GetID()) && should_load_spells) {
  3411. //database.LoadCharacterActiveSpells(player);
  3412. player->UnlockAllSpells(true);
  3413. should_load_spells = false;
  3414. }
  3415. if (spawn_removal_timer.Check() && GetPlayer()) {
  3416. GetPlayer()->ProcessSpawnRangeUpdates();
  3417. GetPlayer()->CheckSpawnStateQueue();
  3418. }
  3419. if (delayedLogin && delayTimer.Enabled() && delayTimer.Check())
  3420. {
  3421. if (!HandleNewLogin(delayedAccountID, delayedAccessKey))
  3422. return false;
  3423. }
  3424. if (quest_updates) {
  3425. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, ProcessQuestUpdates", __FUNCTION__, __LINE__);
  3426. ProcessQuestUpdates();
  3427. }
  3428. int32 queue_timer_delay = rule_manager.GetZoneRule(GetCurrentZoneID(), R_Client, QuestQueueTimer)->GetInt32();
  3429. if (queue_timer_delay < 10) {
  3430. queue_timer_delay = 10;
  3431. }
  3432. if (last_update_time > 0 && last_update_time < (Timer::GetCurrentTime2() - queue_timer_delay)) {
  3433. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, CheckQuestQueue", __FUNCTION__, __LINE__);
  3434. CheckQuestQueue();
  3435. }
  3436. MSaveSpellStateMutex.lock();
  3437. if (save_spell_state_timer.Check())
  3438. {
  3439. save_spell_state_timer.Disable();
  3440. GetPlayer()->SaveSpellEffects();
  3441. }
  3442. MSaveSpellStateMutex.unlock();
  3443. if (temp_placement_timer.Check()) {
  3444. if (GetTempPlacementSpawn() && GetPlayer()->WasSentSpawn(GetTempPlacementSpawn()->GetID()) && !hasSentTempPlacementSpawn) {
  3445. int8 placement = 0;
  3446. int32 uniqueID = GetPlacementUniqueItemID();
  3447. Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  3448. if (uniqueItem && uniqueItem->houseitem_info)
  3449. placement = uniqueItem->houseitem_info->house_location;
  3450. SendMoveObjectMode(GetTempPlacementSpawn(), placement);
  3451. hasSentTempPlacementSpawn = true;
  3452. temp_placement_timer.Disable();
  3453. }
  3454. }
  3455. if (GetCurrentZone() && pos_update.Check())
  3456. {
  3457. ProcessStateCommands();
  3458. GetPlayer()->ResetMentorship(); // check if we need to asynchronously reset mentorship
  3459. if (GetPlayer()->GetRegionMap())
  3460. GetPlayer()->GetRegionMap()->TicRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  3461. if (!player_pos_changed && IsReadyForUpdates() && player_pos_timer < Timer::GetCurrentTime2() && enabled_player_pos_timer) {
  3462. if (version > 373) {
  3463. GetPlayer()->info_changed = true;
  3464. GetPlayer()->vis_changed = true;
  3465. GetPlayer()->position_changed = true;
  3466. GetPlayer()->changed = true;
  3467. GetPlayer()->AddChangedZoneSpawn();
  3468. }
  3469. player_pos_timer = Timer::GetCurrentTime2() + 5000;
  3470. enabled_player_pos_timer = false;
  3471. }
  3472. if (player_pos_changed && IsReadyForUpdates()) {
  3473. player_pos_timer = Timer::GetCurrentTime2() + 500;
  3474. enabled_player_pos_timer = true;
  3475. if (!underworld_cooldown_timer.Enabled() || (underworld_cooldown_timer.Enabled() && underworld_cooldown_timer.Check())) {
  3476. bool underworld = false;
  3477. if (rule_manager.GetZoneRule(GetCurrentZoneID(), R_Zone, UseMapUnderworldCoords)->GetBool()) {
  3478. if (GetCurrentZone() && GetCurrentZone()->GetUnderWorld() != -1000000.0f) {
  3479. if (GetPlayer()->GetY() < GetCurrentZone()->GetUnderWorld())
  3480. underworld = true;
  3481. }
  3482. else if (GetPlayer()->GetMap() && GetPlayer()->GetMap()->GetMinY() != 9999999.0f && GetPlayer()->GetY() < (GetPlayer()->GetMap()->GetMinY() + rule_manager.GetZoneRule(GetCurrentZoneID(), R_Zone, MapUnderworldCoordOffset)->GetFloat())) {
  3483. underworld = true;
  3484. }
  3485. }
  3486. else if (GetPlayer()->GetMap() && GetPlayer()->GetY() < GetCurrentZone()->GetUnderWorld()) {
  3487. underworld = true;
  3488. }
  3489. if (underworld && GetCurrentZone()) {
  3490. player->SetX(GetCurrentZone()->GetSafeX());
  3491. player->SetY(GetCurrentZone()->GetSafeY());
  3492. player->SetZ(GetCurrentZone()->GetSafeZ());
  3493. player->SetHeading(GetCurrentZone()->GetSafeHeading());
  3494. EQ2Packet* app = GetPlayer()->Move(player->GetX(), player->GetY(), player->GetZ(), GetVersion(), player->GetHeading());
  3495. if (app) {
  3496. QueuePacket(app);
  3497. }
  3498. SimpleMessage(CHANNEL_COLOR_RED, "You have been teleported to a safe location in the zone, because you appeared to have fallen through the world.");
  3499. }
  3500. underworld_cooldown_timer.Start();
  3501. }
  3502. //GetPlayer()->CalculateLocation();
  3503. client_list.CheckPlayersInvisStatus(this);
  3504. player_pos_changed = false;
  3505. GetCurrentZone()->CheckTransporters(this);
  3506. if (GetPlayer()->GetRegionMap())
  3507. {
  3508. GetPlayer()->GetRegionMap()->MapRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  3509. }
  3510. }
  3511. else if (IsReadyForUpdates() && GetPlayer()->GetRegionMap()) {
  3512. GetPlayer()->GetRegionMap()->UpdateRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  3513. }
  3514. }
  3515. if (lua_interface && lua_debug && lua_debug_timer.Check())
  3516. lua_interface->UpdateDebugClients(this);
  3517. if (quest_pos_timer.Check())
  3518. CheckPlayerQuestsLocationUpdate();
  3519. if (player->GetSkills()->HasSkillUpdates()) {
  3520. vector<Skill*>* skills = player->GetSkills()->GetSkillUpdates();
  3521. if (skills) {
  3522. Skill* skill = 0;
  3523. vector<Skill*>::iterator itr;
  3524. for (itr = skills->begin(); itr != skills->end(); itr++) {
  3525. skill = *itr;
  3526. SkillChanged(skill, skill->previous_val, skill->current_val);
  3527. }
  3528. EQ2Packet* app = GetPlayer()->skill_list.GetSkillPacket(GetVersion());
  3529. if (app) QueuePacket(app);
  3530. safe_delete(skills);
  3531. }
  3532. }
  3533. m_resurrect.writelock(__FUNCTION__, __LINE__);
  3534. if (current_rez.should_delete || (current_rez.expire_timer && current_rez.expire_timer->Check(false))) {
  3535. safe_delete(current_rez.expire_timer);
  3536. current_rez.expire_timer = 0;
  3537. current_rez.active = false;
  3538. current_rez.caster = 0;
  3539. current_rez.crit = false;
  3540. current_rez.crit_mod = 0;
  3541. current_rez.expire_timer = 0;
  3542. current_rez.heal_name = "";
  3543. current_rez.hp_perc = 0;
  3544. current_rez.mp_perc = 0;
  3545. current_rez.no_calcs = false;
  3546. current_rez.range = 0;
  3547. current_rez.should_delete = false;
  3548. current_rez.spell_name = "";
  3549. current_rez.spell_visual = 0;
  3550. current_rez.subspell = 0;
  3551. }
  3552. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  3553. // Quest timers
  3554. Quest* failed_step = 0;
  3555. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  3556. if (quest_timers.size() > 0) {
  3557. vector<int32>::iterator itr;
  3558. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  3559. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  3560. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  3561. if (player_quests->count(*itr) > 0 && player_quests->at(*itr)->GetStepTimer() != 0) {
  3562. Quest* quest = player_quests->at(*itr);
  3563. if (Timer::GetUnixTimeStamp() >= quest->GetStepTimer()) {
  3564. failed_step = quest;
  3565. break;
  3566. }
  3567. }
  3568. else {
  3569. itr = quest_timers.erase(itr);
  3570. break;
  3571. }
  3572. }
  3573. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  3574. }
  3575. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  3576. if (failed_step)
  3577. failed_step->StepFailed(failed_step->GetTimerStep());
  3578. if (player->ControlFlagsChanged())
  3579. player->SendControlFlagUpdates(this);
  3580. if (!eqs || (eqs && !eqs->CheckActive()))
  3581. ret = false;
  3582. // redundant to client disconnect
  3583. // if(!ret)
  3584. // Save();
  3585. return ret;
  3586. }
  3587. ClientList::ClientList() {
  3588. MClients.SetName("ClientList::MClients");
  3589. }
  3590. ClientList::~ClientList() {
  3591. }
  3592. void ClientList::ReloadQuests() {
  3593. list<Client*>::iterator client_iter;
  3594. Client* client = 0;
  3595. MClients.readlock(__FUNCTION__, __LINE__);
  3596. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3597. client = *client_iter;
  3598. if (client)
  3599. client->ReloadQuests();
  3600. }
  3601. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3602. }
  3603. void ClientList::CheckPlayersInvisStatus(Client* owner) {
  3604. if (!owner->GetPlayer() || (!owner->GetPlayer()->IsInvis() && !owner->GetPlayer()->IsStealthed()))
  3605. return;
  3606. list<Client*>::iterator client_iter;
  3607. Client* client = 0;
  3608. MClients.readlock(__FUNCTION__, __LINE__);
  3609. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3610. client = *client_iter;
  3611. if (client == owner || client->GetPlayer() == NULL)
  3612. continue;
  3613. if (client->GetPlayer()->CheckChangeInvisHistory((Entity*)owner->GetPlayer()))
  3614. client->GetPlayer()->GetZone()->SendSpawnChanges(owner->GetPlayer(), client, true, true);
  3615. }
  3616. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3617. }
  3618. void ClientList::RemovePlayerFromInvisHistory(int32 spawnID) {
  3619. list<Client*>::iterator client_iter;
  3620. Client* client = 0;
  3621. MClients.readlock(__FUNCTION__, __LINE__);
  3622. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3623. client = *client_iter;
  3624. if (!client->GetPlayer())
  3625. continue;
  3626. client->GetPlayer()->RemoveTargetInvisHistory(spawnID);
  3627. }
  3628. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3629. }
  3630. int32 ClientList::Count() {
  3631. return client_list.size();
  3632. }
  3633. void ClientList::Add(Client* client) {
  3634. MClients.writelock(__FUNCTION__, __LINE__);
  3635. client_list.push_back(client);
  3636. MClients.releasewritelock(__FUNCTION__, __LINE__);
  3637. }
  3638. Client* ClientList::FindByAccountID(int32 account_id) {
  3639. list<Client*>::iterator client_iter;
  3640. Client* client = 0;
  3641. Client* ret = 0;
  3642. MClients.readlock(__FUNCTION__, __LINE__);
  3643. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3644. client = *client_iter;
  3645. if (client->GetAccountID() == account_id) {
  3646. ret = client;
  3647. break;
  3648. }
  3649. }
  3650. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3651. return ret;
  3652. }
  3653. Client* ClientList::FindByName(char* charName) {
  3654. list<Client*>::iterator client_iter;
  3655. Client* client = 0;
  3656. Client* ret = 0;
  3657. MClients.readlock(__FUNCTION__, __LINE__);
  3658. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3659. client = *client_iter;
  3660. if (!client || !client->GetPlayer())
  3661. continue;
  3662. if (!strncmp(client->GetPlayer()->GetName(), charName, strlen(charName))) {
  3663. ret = client;
  3664. break;
  3665. }
  3666. }
  3667. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3668. return ret;
  3669. }
  3670. Client* ClientList::Get(int32 ip, int16 port) {
  3671. list<Client*>::iterator client_iter;
  3672. Client* client = 0;
  3673. Client* ret = 0;
  3674. MClients.readlock(__FUNCTION__, __LINE__);
  3675. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3676. client = *client_iter;
  3677. if (client->GetIP() == ip && client->GetPort() == port) {
  3678. ret = client;
  3679. break;
  3680. }
  3681. }
  3682. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3683. return ret;
  3684. }
  3685. void ClientList::Process() {
  3686. list<Client*>::iterator client_iter;
  3687. list<Client*>::iterator erase_iter;
  3688. Client* client = 0;
  3689. MClients.readlock(__FUNCTION__, __LINE__);
  3690. erase_iter = client_list.end();
  3691. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3692. client = *client_iter;
  3693. // have a sanity check because the client list can sometimes obtain null client pointers
  3694. if (!client || client->remove_from_list || (!client->Process())) { // if we should be removing from list, don't process any further
  3695. erase_iter = client_iter;
  3696. break;
  3697. }
  3698. }
  3699. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3700. if (erase_iter != client_list.end()) {
  3701. client = *erase_iter;
  3702. MClients.writelock(__FUNCTION__, __LINE__);
  3703. client_list.erase(erase_iter);
  3704. MClients.releasewritelock(__FUNCTION__, __LINE__);
  3705. if (client && !client->remove_from_list) {
  3706. struct in_addr in;
  3707. in.s_addr = client->GetIP();
  3708. LogWrite(WORLD__INFO, 0, "World", "Removing client from ip: %s port: %i", inet_ntoa(in), client->GetPort());
  3709. safe_delete(client);
  3710. }
  3711. }
  3712. }
  3713. void ClientList::RemoveConnection(EQStream* eqs) {
  3714. Client* client;
  3715. if (eqs) {
  3716. list<Client*>::iterator client_iter;
  3717. MClients.readlock(__FUNCTION__, __LINE__);
  3718. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3719. client = *client_iter;
  3720. if (client->getConnection() == eqs)
  3721. client->Disconnect(true);
  3722. }
  3723. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3724. }
  3725. }
  3726. bool ClientList::ContainsStream(EQStream* eqs) {
  3727. if (!eqs) {
  3728. return false;
  3729. }
  3730. list<Client*>::iterator client_iter;
  3731. bool ret = false;
  3732. MClients.readlock(__FUNCTION__, __LINE__);
  3733. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3734. if ((*client_iter)->getConnection() && (*client_iter)->getConnection()->GetRemotePort() == eqs->GetRemotePort() && (*client_iter)->getConnection()->GetRemoteIP() == eqs->GetRemoteIP()) {
  3735. ret = true;
  3736. break;
  3737. }
  3738. }
  3739. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3740. return ret;
  3741. }
  3742. void ClientList::Remove(Client* client, bool remove_data) {
  3743. client->remove_from_list = true;
  3744. if (remove_data) {
  3745. safe_delete(client);
  3746. }
  3747. }
  3748. void Client::SetCurrentZone(ZoneServer* zone) {
  3749. current_zone = zone;
  3750. if (player) {
  3751. player->SetZone(zone, GetVersion());
  3752. }
  3753. }
  3754. void Client::SetCurrentZone(int32 id) {
  3755. if (current_zone) {
  3756. //current_zone->GetCombat()->RemoveHate(player);
  3757. current_zone->RemoveSpawn(player, false, true, true, true, true);
  3758. }
  3759. ZoneChangeDetails zone_details;
  3760. if (zone_list.GetZone(&zone_details, id, "", true, false, true, false)) {
  3761. SetCurrentZone((ZoneServer*)zone_details.zonePtr);
  3762. }
  3763. }
  3764. void Client::SetCurrentZoneByInstanceID(int32 id, int32 zoneid) {
  3765. if (current_zone) {
  3766. //current_zone->GetCombat()->RemoveHate(player);
  3767. current_zone->RemoveSpawn(player, false, true, true, true, true);
  3768. }
  3769. ZoneChangeDetails zone_details;
  3770. if (zone_list.GetZoneByInstance(&zone_details, id, zoneid, true, false, true, false)) {
  3771. SetCurrentZone((ZoneServer*)zone_details.zonePtr);
  3772. }
  3773. else {
  3774. LogWrite(CCLIENT__ERROR, 0, "Client", "Failed to Client::SetCurrentZoneByInstanceID(id = %u, zoneid = %u) for Player %s.", id, zoneid, GetPlayer()->GetName());
  3775. }
  3776. }
  3777. ZoneServer* Client::GetCurrentZone() {
  3778. return current_zone;
  3779. }
  3780. int32 Client::GetCurrentZoneID() {
  3781. return current_zone ? current_zone->GetZoneID() : 0;
  3782. }
  3783. int8 Client::GetMessageChannelColor(int8 channel_type) {
  3784. if (GetVersion() >= 973 && GetVersion() <= 1000) {
  3785. if (channel_type == CHANNEL_LOOT)
  3786. return CHANNEL_COLOR_NEW_LOOT;
  3787. }
  3788. else if (GetVersion() >= 973) {
  3789. if (channel_type == CHANNEL_LOOT)
  3790. return CHANNEL_COLOR_NEWEST_LOOT;
  3791. }
  3792. if (GetVersion() <= 283) {
  3793. if (channel_type <= 12)
  3794. return channel_type;
  3795. switch (channel_type) {
  3796. case CHANNEL_GROUP_CHAT:
  3797. case CHANNEL_GROUP_SAY:
  3798. case CHANNEL_RAID_SAY:
  3799. case CHANNEL_GUILD_CHAT:
  3800. case CHANNEL_GUILD_SAY:
  3801. case CHANNEL_OFFICER_SAY:
  3802. case CHANNEL_GUILD_MOTD:
  3803. return channel_type - 1;
  3804. case CHANNEL_PRIVATE_CHAT:
  3805. case CHANNEL_NONPLAYER_TELL:
  3806. return channel_type - 5;
  3807. case CHANNEL_PRIVATE_TELL:
  3808. case CHANNEL_TELL_FROM_CS:
  3809. return channel_type - 6;
  3810. case CHANNEL_CHAT_CHANNEL_TEXT:
  3811. case CHANNEL_OUT_OF_CHARACTER:
  3812. case CHANNEL_AUCTION:
  3813. case CHANNEL_CUSTOM_CHANNEL:
  3814. case CHANNEL_CHARACTER_TEXT:
  3815. case CHANNEL_REWARD:
  3816. case CHANNEL_DEATH:
  3817. case CHANNEL_PET_CHAT:
  3818. case CHANNEL_SKILL:
  3819. return channel_type - 7;
  3820. case CHANNEL_SPELLS:
  3821. case CHANNEL_YOU_CAST:
  3822. case CHANNEL_YOU_FAIL:
  3823. return channel_type - 8;
  3824. case CHANNEL_FRIENDLY_CAST:
  3825. case CHANNEL_FRIENDLY_FAIL:
  3826. case CHANNEL_OTHER_CAST:
  3827. case CHANNEL_OTHER_FAIL:
  3828. case CHANNEL_HOSTILE_CAST:
  3829. case CHANNEL_HOSTILE_FAIL:
  3830. case CHANNEL_WORN_OFF:
  3831. case CHANNEL_SPELLS_OTHER:
  3832. return channel_type - 9;
  3833. case CHANNEL_COMBAT:
  3834. return channel_type - 15;
  3835. case CHANNEL_HEROIC_OPPORTUNITY:
  3836. case CHANNEL_NON_MELEE_DAMAGE:
  3837. case CHANNEL_DAMAGE_SHIELD:
  3838. return channel_type - 16;
  3839. case CHANNEL_MELEE_COMBAT:
  3840. case CHANNEL_WARNINGS:
  3841. case CHANNEL_YOU_HIT:
  3842. case CHANNEL_YOU_MISS:
  3843. case CHANNEL_ATTACKER_HITS:
  3844. case CHANNEL_ATTACKER_MISSES:
  3845. return channel_type - 18;
  3846. case CHANNEL_OTHER_HIT:
  3847. case CHANNEL_OTHER_MISSES:
  3848. case CHANNEL_CRITICAL_HIT:
  3849. return channel_type - 22;
  3850. case CHANNEL_OTHER:
  3851. case CHANNEL_MONEY_SPLIT:
  3852. case CHANNEL_LOOT:
  3853. return channel_type - 30;
  3854. case CHANNEL_COMMAND_TEXT:
  3855. case CHANNEL_BROADCAST:
  3856. case CHANNEL_WHO:
  3857. case CHANNEL_COMMANDS:
  3858. case CHANNEL_MERCHANT:
  3859. case CHANNEL_MERCHANT_BUY_SELL:
  3860. case CHANNEL_CONSIDER_MESSAGE:
  3861. case CHANNEL_CON_MINUS_2:
  3862. case CHANNEL_CON_MINUS_1:
  3863. case CHANNEL_CON_0:
  3864. case CHANNEL_CON_1:
  3865. case CHANNEL_CON_2:
  3866. return channel_type - 31;
  3867. default: {
  3868. return CHANNEL_DEFAULT;
  3869. }
  3870. }
  3871. }
  3872. else if (GetVersion() <= 373) {
  3873. if (channel_type <= 18)
  3874. return channel_type;
  3875. switch (channel_type) {
  3876. case CHANNEL_PRIVATE_CHAT:
  3877. case CHANNEL_NONPLAYER_TELL:
  3878. return 22;
  3879. case CHANNEL_PRIVATE_TELL:
  3880. case CHANNEL_TELL_FROM_CS:
  3881. return 23;
  3882. case CHANNEL_CHAT_CHANNEL_TEXT:
  3883. case CHANNEL_OUT_OF_CHARACTER:
  3884. case CHANNEL_CUSTOM_CHANNEL:
  3885. case CHANNEL_CHARACTER_TEXT:
  3886. case CHANNEL_REWARD:
  3887. case CHANNEL_DEATH:
  3888. case CHANNEL_PET_CHAT:
  3889. case CHANNEL_SKILL:
  3890. return 26;
  3891. case CHANNEL_AUCTION:
  3892. return 27;
  3893. case CHANNEL_SPELLS:
  3894. case CHANNEL_YOU_CAST:
  3895. case CHANNEL_YOU_FAIL:
  3896. return channel_type - 8;
  3897. case CHANNEL_FRIENDLY_CAST:
  3898. case CHANNEL_FRIENDLY_FAIL:
  3899. case CHANNEL_OTHER_CAST:
  3900. case CHANNEL_OTHER_FAIL:
  3901. case CHANNEL_HOSTILE_CAST:
  3902. case CHANNEL_HOSTILE_FAIL:
  3903. case CHANNEL_WORN_OFF:
  3904. case CHANNEL_SPELLS_OTHER:
  3905. return channel_type - 9;
  3906. case CHANNEL_COMBAT:
  3907. return channel_type - 15;
  3908. case CHANNEL_HEROIC_OPPORTUNITY:
  3909. case CHANNEL_NON_MELEE_DAMAGE:
  3910. case CHANNEL_DAMAGE_SHIELD:
  3911. return channel_type - 16;
  3912. case CHANNEL_MELEE_COMBAT:
  3913. case CHANNEL_WARNINGS:
  3914. case CHANNEL_YOU_HIT:
  3915. case CHANNEL_YOU_MISS:
  3916. case CHANNEL_ATTACKER_HITS:
  3917. case CHANNEL_ATTACKER_MISSES:
  3918. return channel_type - 18;
  3919. case CHANNEL_OTHER_HIT:
  3920. case CHANNEL_OTHER_MISSES:
  3921. case CHANNEL_CRITICAL_HIT:
  3922. return channel_type - 22;
  3923. case CHANNEL_OTHER:
  3924. case CHANNEL_MONEY_SPLIT:
  3925. case CHANNEL_LOOT:
  3926. return channel_type - 30;
  3927. case CHANNEL_COMMAND_TEXT:
  3928. case CHANNEL_BROADCAST:
  3929. case CHANNEL_WHO:
  3930. case CHANNEL_COMMANDS:
  3931. case CHANNEL_MERCHANT:
  3932. case CHANNEL_MERCHANT_BUY_SELL:
  3933. case CHANNEL_CONSIDER_MESSAGE:
  3934. case CHANNEL_CON_MINUS_2:
  3935. case CHANNEL_CON_MINUS_1:
  3936. case CHANNEL_CON_0:
  3937. case CHANNEL_CON_1:
  3938. case CHANNEL_CON_2:
  3939. return 68;
  3940. default: {
  3941. return CHANNEL_DEFAULT;
  3942. }
  3943. }
  3944. }
  3945. else if (GetVersion() <= 561) {
  3946. if (channel_type < 20)
  3947. return channel_type;
  3948. switch (channel_type) {
  3949. case CHANNEL_GUILD_MOTD:
  3950. case CHANNEL_GUILD_MEMBER_ONLINE:
  3951. case CHANNEL_GUILD_EVENT:
  3952. return channel_type + 1;
  3953. case CHANNEL_PRIVATE_CHAT:
  3954. case CHANNEL_NONPLAYER_TELL:
  3955. return channel_type - 1;
  3956. case CHANNEL_PRIVATE_TELL:
  3957. case CHANNEL_TELL_FROM_CS:
  3958. case CHANNEL_ARENA:
  3959. case CHANNEL_CHAT_CHANNEL_TEXT:
  3960. case CHANNEL_OUT_OF_CHARACTER:
  3961. case CHANNEL_AUCTION:
  3962. case CHANNEL_CUSTOM_CHANNEL:
  3963. case CHANNEL_CHARACTER_TEXT:
  3964. case CHANNEL_REWARD:
  3965. case CHANNEL_DEATH:
  3966. case CHANNEL_PET_CHAT:
  3967. case CHANNEL_SKILL:
  3968. case CHANNEL_FACTION:
  3969. case CHANNEL_SPELLS:
  3970. case CHANNEL_YOU_CAST:
  3971. case CHANNEL_YOU_FAIL:
  3972. return channel_type - 2;
  3973. case CHANNEL_FRIENDLY_CAST:
  3974. case CHANNEL_FRIENDLY_FAIL:
  3975. case CHANNEL_OTHER_CAST:
  3976. case CHANNEL_OTHER_FAIL:
  3977. case CHANNEL_HOSTILE_CAST:
  3978. case CHANNEL_HOSTILE_FAIL:
  3979. case CHANNEL_WORN_OFF:
  3980. case CHANNEL_SPELLS_OTHER:
  3981. case CHANNEL_HEAL_SPELLS:
  3982. case CHANNEL_HEALS:
  3983. case CHANNEL_FRIENDLY_HEALS:
  3984. case CHANNEL_OTHER_HEALS:
  3985. case CHANNEL_HOSTILE_HEALS:
  3986. return channel_type - 3;
  3987. case CHANNEL_COMBAT:
  3988. case CHANNEL_GENERAL_COMBAT:
  3989. case CHANNEL_HEROIC_OPPORTUNITY:
  3990. case CHANNEL_NON_MELEE_DAMAGE:
  3991. case CHANNEL_DAMAGE_SHIELD:
  3992. case CHANNEL_WARD:
  3993. return channel_type - 4;
  3994. case CHANNEL_MELEE_COMBAT:
  3995. case CHANNEL_WARNINGS:
  3996. case CHANNEL_YOU_HIT:
  3997. case CHANNEL_YOU_MISS:
  3998. case CHANNEL_ATTACKER_HITS:
  3999. case CHANNEL_ATTACKER_MISSES:
  4000. case CHANNEL_YOUR_PET_HITS:
  4001. case CHANNEL_YOUR_PET_MISSES:
  4002. case CHANNEL_ATTACKER_HITS_PET:
  4003. case CHANNEL_ATTACKER_MISSES_PET:
  4004. case CHANNEL_OTHER_HIT:
  4005. case CHANNEL_OTHER_MISSES:
  4006. return channel_type - 5;
  4007. case CHANNEL_OTHER:
  4008. case CHANNEL_MONEY_SPLIT:
  4009. case CHANNEL_LOOT:
  4010. return channel_type - 14;
  4011. case CHANNEL_COMMAND_TEXT:
  4012. case CHANNEL_BROADCAST:
  4013. case CHANNEL_WHO:
  4014. case CHANNEL_COMMANDS:
  4015. case CHANNEL_MERCHANT:
  4016. case CHANNEL_MERCHANT_BUY_SELL:
  4017. case CHANNEL_CONSIDER_MESSAGE:
  4018. case CHANNEL_CON_MINUS_2:
  4019. case CHANNEL_CON_MINUS_1:
  4020. case CHANNEL_CON_0:
  4021. case CHANNEL_CON_1:
  4022. case CHANNEL_CON_2:
  4023. case CHANNEL_TRADESKILLS:
  4024. case CHANNEL_HARVESTING:
  4025. case CHANNEL_HARVESTING_WARNINGS:
  4026. return channel_type - 15;
  4027. default: {
  4028. return CHANNEL_DEFAULT;
  4029. }
  4030. }
  4031. }
  4032. else {
  4033. switch (channel_type) {
  4034. default: {
  4035. return channel_type;
  4036. }
  4037. }
  4038. }
  4039. return channel_type;
  4040. }
  4041. void Client::HandleTellMessage(const char* fromName, const char* message, const char* to, int32 current_language_id) {
  4042. if (!fromName || !to || GetPlayer()->IsIgnored(fromName))
  4043. return;
  4044. PacketStruct* packet = configReader.getStruct("WS_HearChat", GetVersion());
  4045. if (packet) {
  4046. packet->setDataByName("from", fromName);
  4047. packet->setDataByName("to", to);
  4048. packet->setDataByName("channel", GetMessageChannelColor(CHANNEL_PRIVATE_TELL));
  4049. packet->setDataByName("from_spawn_id", 0xFFFFFFFF);
  4050. packet->setDataByName("to_spawn_id", 0xFFFFFFFF);
  4051. packet->setDataByName("unknown2", 1, 1);
  4052. packet->setDataByName("show_bubble", 1);
  4053. if (current_language_id == 0 || GetPlayer()->HasLanguage(current_language_id)) {
  4054. packet->setDataByName("understood", 1);
  4055. }
  4056. packet->setDataByName("time", 2);
  4057. packet->setDataByName("language", current_language_id);
  4058. packet->setMediumStringByName("message", message);
  4059. EQ2Packet* outpacket = packet->serialize();
  4060. QueuePacket(outpacket);
  4061. safe_delete(packet);
  4062. }
  4063. }
  4064. void Client::SimpleMessage(int8 color, const char* message) {
  4065. PacketStruct* command_packet = configReader.getStruct("WS_DisplayText", GetVersion());
  4066. if (command_packet) {
  4067. command_packet->setDataByName("color", GetMessageChannelColor(color));//convert this to the correct client type (different clients have different chat numbers)
  4068. command_packet->setMediumStringByName("text", message);
  4069. command_packet->setDataByName("unknown02", 0x00ff);
  4070. EQ2Packet* outapp = command_packet->serialize();
  4071. QueuePacket(outapp);
  4072. safe_delete(command_packet);
  4073. }
  4074. }
  4075. void Client::SendSpellUpdate(Spell* spell, bool add_silently, bool add_to_hotbar) {
  4076. PacketStruct* packet = configReader.getStruct("WS_SpellGainedMsg", GetVersion());
  4077. if (packet) {
  4078. int8 xxx = spell->GetSpellData()->is_aa;
  4079. packet->setDataByName("spell_type", spell->GetSpellData()->type);
  4080. packet->setDataByName("spell_id", spell->GetSpellID());
  4081. packet->setDataByName("unique_id", spell->GetSpellData()->spell_name_crc);
  4082. packet->setDataByName("spell_name", spell->GetName());
  4083. if (add_silently)
  4084. packet->setDataByName("add_silently", 1);
  4085. if (add_to_hotbar)
  4086. packet->setDataByName("add_to_hotbar", 1);
  4087. packet->setDataByName("unknown", xxx);
  4088. packet->setDataByName("display_spell_tier", 1);
  4089. packet->setDataByName("unknown3", 1);
  4090. packet->setDataByName("tier", spell->GetSpellTier());
  4091. packet->setDataByName("icon", spell->GetSpellIcon());
  4092. packet->setDataByName("icon_type", spell->GetSpellIconBackdrop());
  4093. packet->setDataByName("unknown5", 0xFFFFFFFF);
  4094. //packet->PrintPacket();
  4095. EQ2Packet* outapp = packet->serialize();
  4096. //DumpPacket(outapp);
  4097. QueuePacket(outapp);
  4098. safe_delete(packet);
  4099. }
  4100. }
  4101. void Client::Message(int8 type, const char* message, ...) {
  4102. va_list argptr;
  4103. char buffer[4096];
  4104. va_start(argptr, message);
  4105. vsnprintf(buffer, sizeof(buffer), message, argptr);
  4106. va_end(argptr);
  4107. SimpleMessage(type, buffer);
  4108. }
  4109. void Client::Disconnect(bool send_disconnect)
  4110. {
  4111. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client Disconnect...");
  4112. this->Save();
  4113. this->GetPlayer()->WritePlayerStatistics();
  4114. SetConnected(false);
  4115. if (send_disconnect && getConnection())
  4116. getConnection()->SendDisconnect(true);
  4117. eqs = 0;
  4118. }
  4119. bool Client::Summon(const char* search_name) {
  4120. Spawn* target = 0;
  4121. if (search_name || GetPlayer()->GetTarget()) {
  4122. Client* search_client = 0;
  4123. if (search_name) {
  4124. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  4125. if (target && target->IsPlayer())
  4126. search_client = target->GetClient();
  4127. if (!target) {
  4128. search_client = zone_list.GetClientByCharName(string(search_name));
  4129. if (search_client)
  4130. target = search_client->GetPlayer();
  4131. }
  4132. }
  4133. else
  4134. target = GetPlayer()->GetTarget();
  4135. if (target && target != GetPlayer()) {
  4136. target->SetX(GetPlayer()->GetX());
  4137. target->SetY(GetPlayer()->GetY());
  4138. target->SetZ(GetPlayer()->GetZ());
  4139. target->SetHeading(GetPlayer()->GetHeading());
  4140. if (!target->IsPlayer()) {
  4141. target->SetSpawnOrigX(target->GetX());
  4142. target->SetSpawnOrigY(target->GetY());
  4143. target->SetSpawnOrigZ(target->GetZ());
  4144. target->SetSpawnOrigHeading(target->GetHeading());
  4145. }
  4146. target->SetLocation(GetPlayer()->GetLocation());
  4147. if (target->IsNPC()) {
  4148. ((NPC*)target)->HaltMovement();
  4149. }
  4150. }
  4151. else if (target)
  4152. Message(CHANNEL_COLOR_RED, "Error: You cannot summon yourself!");
  4153. if (search_client && search_client != this) {
  4154. search_client->Message(CHANNEL_COLOR_YELLOW, "You have been summoned by '%s'!", GetPlayer()->GetName());
  4155. Message(CHANNEL_COLOR_YELLOW, "Summoning '%s'...", search_client->GetPlayer()->GetName());
  4156. if (search_client->GetCurrentZone() != GetCurrentZone())
  4157. search_client->Zone(GetCurrentZone()->GetZoneName(), false);
  4158. else {
  4159. EQ2Packet* app = search_client->GetPlayer()->Move(GetPlayer()->GetX(), GetPlayer()->GetY(), GetPlayer()->GetZ(), search_client->GetVersion());
  4160. if (app)
  4161. search_client->QueuePacket(app);
  4162. }
  4163. }
  4164. }
  4165. if (!target)
  4166. return false;
  4167. else
  4168. return true;
  4169. }
  4170. std::string Client::IdentifyInstanceLockout(int32 zoneID, bool displayClient) {
  4171. int8 instanceType = database.GetInstanceTypeByZoneID(zoneID);
  4172. if (instanceType < 1)
  4173. return std::string("");
  4174. ZoneServer* instance_zone = nullptr;
  4175. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  4176. if (data) {
  4177. // If lockout instances check to see if we are locked out
  4178. if (instanceType == SOLO_LOCKOUT_INSTANCE || instanceType == GROUP_LOCKOUT_INSTANCE || instanceType == RAID_LOCKOUT_INSTANCE) {
  4179. int32 time = 0;
  4180. // Check success timer
  4181. if (data->last_success_timestamp > 0) {
  4182. if (Timer::GetUnixTimeStamp() < data->last_success_timestamp + data->success_lockout_time) {
  4183. // Timer has not expired yet can't re enter
  4184. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Success lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  4185. time = (data->last_success_timestamp + data->success_lockout_time) - Timer::GetUnixTimeStamp();
  4186. }
  4187. }
  4188. // Check failure timer
  4189. if (data->last_failure_timestamp > 0) {
  4190. if (Timer::GetUnixTimeStamp() < data->last_failure_timestamp + data->failure_lockout_time) {
  4191. // Timer has not expired yet
  4192. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Failure lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  4193. time = (data->last_failure_timestamp + data->failure_lockout_time) - Timer::GetUnixTimeStamp();
  4194. }
  4195. }
  4196. // Time > 0 then we are locked out, make the message and send it and return true
  4197. if (time > 0) {
  4198. string time_msg = "";
  4199. int16 hour;
  4200. int8 min;
  4201. int8 sec;
  4202. hour = time / 3600;
  4203. time = time % 3600;
  4204. min = time / 60;
  4205. time = time % 60;
  4206. sec = time;
  4207. if (hour > 0) {
  4208. char temp[10];
  4209. snprintf(temp, 9, " %i", hour);
  4210. time_msg.append(temp);
  4211. time_msg.append(" hour");
  4212. time_msg.append((hour > 1) ? "s" : "");
  4213. }
  4214. if (min > 0) {
  4215. char temp[5];
  4216. snprintf(temp, 4, " %i", min);
  4217. time_msg.append(temp);
  4218. time_msg.append(" minute");
  4219. time_msg.append((min > 1) ? "s" : "");
  4220. }
  4221. // Only add seconds if minutes and hours are 0
  4222. if (hour == 0 && min == 0 && sec > 0) {
  4223. char temp[5];
  4224. snprintf(temp, 4, " %i", sec);
  4225. time_msg.append(temp);
  4226. time_msg.append(" second");
  4227. time_msg.append((sec > 1) ? "s" : "");
  4228. }
  4229. if (displayClient)
  4230. Message(CHANNEL_COLOR_YELLOW, "You may not enter again for%s.", time_msg.c_str());
  4231. return time_msg;
  4232. }
  4233. }
  4234. }
  4235. return std::string("");
  4236. }
  4237. bool Client::IdentifyInstance(ZoneChangeDetails* zone_details, int32 zoneID) {
  4238. int8 instanceType = database.GetInstanceTypeByZoneID(zoneID);
  4239. if (instanceType < 1)
  4240. return false;
  4241. bool foundZone = false;
  4242. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  4243. if (data) {
  4244. std::string lockoutTime = IdentifyInstanceLockout(zoneID);
  4245. // If lockout instances check to see if we are locked out
  4246. if (lockoutTime.length() > 0) {
  4247. return false;
  4248. }
  4249. // Need to update `character_instances` table with new timestamps (for persistent) and instance id's
  4250. foundZone = zone_list.GetZoneByInstance(zone_details, data->instance_id, zoneID, true, false, false);
  4251. // 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
  4252. if (foundZone && (data->instance_id == 0 || data->instance_id != zone_details->instanceId)) {
  4253. if (instanceType == SOLO_PERSIST_INSTANCE || instanceType == GROUP_PERSIST_INSTANCE || instanceType == RAID_PERSIST_INSTANCE) {
  4254. database.UpdateCharacterInstance(GetCharacterID(), zone_details->zoneName, zone_details->instanceId, 1, Timer::GetUnixTimeStamp());
  4255. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  4256. }
  4257. else
  4258. database.UpdateCharacterInstance(GetCharacterID(), zone_details->zoneName, zone_details->instanceId);
  4259. data->instance_id = zone_details->instanceId;
  4260. }
  4261. }
  4262. return foundZone;
  4263. }
  4264. bool Client::TryZoneInstance(int32 zoneID, bool zone_coords_valid) {
  4265. ZoneServer* instance_zone = NULL;
  4266. int8 instanceType = 0;
  4267. bool foundZone = false;
  4268. ZoneChangeDetails zone_details;
  4269. // determine if this is a group instanced zone that already exists
  4270. foundZone = world.GetGroupManager()->IdentifyMemberInGroupOrRaid(&zone_details, this, zoneID);
  4271. if (foundZone) {
  4272. InstanceData* data = nullptr;
  4273. if (zone_details.instanceId)
  4274. data = GetPlayer()->GetCharacterInstances()->FindInstanceByInstanceID(zone_details.instanceId);
  4275. switch (zone_details.instanceType) {
  4276. case SOLO_LOCKOUT_INSTANCE:
  4277. case GROUP_LOCKOUT_INSTANCE:
  4278. case RAID_LOCKOUT_INSTANCE:
  4279. case SOLO_PERSIST_INSTANCE:
  4280. case GROUP_PERSIST_INSTANCE:
  4281. case RAID_PERSIST_INSTANCE:
  4282. {
  4283. if (!data && zone_details.instanceId) {
  4284. int32 db_id = database.AddCharacterInstance(GetPlayer()->GetCharacterID(), zone_details.instanceId, zone_details.zoneName, zone_details.instanceType, Timer::GetUnixTimeStamp(), 0, zone_details.defaultLockoutTime, zone_details.defaultReenterTime);
  4285. if (db_id > 0)
  4286. GetPlayer()->GetCharacterInstances()->AddInstance(db_id, zone_details.instanceId, Timer::GetUnixTimeStamp(), 0, zone_details.defaultLockoutTime, zone_details.defaultReenterTime, zoneID, zone_details.instanceType, zone_details.zoneName);
  4287. }
  4288. break;
  4289. }
  4290. }
  4291. Zone(&zone_details, instance_zone, zone_coords_valid);
  4292. }
  4293. else if ((instanceType = database.GetInstanceTypeByZoneID(zoneID)) > 0)
  4294. {
  4295. // best to check if we already have our own instance!
  4296. if (!(foundZone = IdentifyInstance(&zone_details, zoneID)))
  4297. {
  4298. switch (instanceType)
  4299. {
  4300. case SOLO_LOCKOUT_INSTANCE:
  4301. case GROUP_LOCKOUT_INSTANCE:
  4302. case RAID_LOCKOUT_INSTANCE:
  4303. {
  4304. if ((foundZone = zone_list.GetZoneByInstance(&zone_details, 0, zoneID))) {
  4305. // 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
  4306. // so delete `instances` entry for the zone when it shuts down.
  4307. int32 db_id = database.AddCharacterInstance(GetPlayer()->GetCharacterID(), zone_details.instanceId, zone_details.zoneName, zone_details.instanceType, 0, 0, zone_details.defaultLockoutTime, zone_details.defaultReenterTime);
  4308. if (db_id > 0)
  4309. GetPlayer()->GetCharacterInstances()->AddInstance(db_id, zone_details.instanceId, 0, 0, zone_details.defaultLockoutTime, zone_details.defaultReenterTime, zoneID, zone_details.instanceType, zone_details.zoneName);
  4310. }
  4311. break;
  4312. }
  4313. case SOLO_PERSIST_INSTANCE:
  4314. case GROUP_PERSIST_INSTANCE:
  4315. case RAID_PERSIST_INSTANCE:
  4316. {
  4317. if ((foundZone = zone_list.GetZoneByInstance(&zone_details, 0, zoneID))) {
  4318. int32 db_id = database.AddCharacterInstance(GetPlayer()->GetCharacterID(), zone_details.instanceId, zone_details.zoneName, zone_details.instanceType, Timer::GetUnixTimeStamp(), 0, zone_details.defaultLockoutTime, zone_details.defaultReenterTime);
  4319. if (db_id > 0)
  4320. GetPlayer()->GetCharacterInstances()->AddInstance(db_id, zone_details.instanceId, Timer::GetUnixTimeStamp(), 0, zone_details.defaultLockoutTime, zone_details.defaultReenterTime, zoneID, zone_details.instanceType, zone_details.zoneName);
  4321. }
  4322. break;
  4323. }
  4324. case PUBLIC_INSTANCE:
  4325. case TRADESKILL_INSTANCE:
  4326. {
  4327. // if its public/tradeskill, look for a public already setup
  4328. instance_zone = zone_list.GetByLowestPopulation(zoneID);
  4329. if (instance_zone) {
  4330. // Check the current population against the max population, if greater or equal start a new version
  4331. if (instance_zone->GetClientCount() >= rule_manager.GetZoneRule(GetCurrentZoneID(), R_Zone, MaxPlayers)->GetInt32()) {
  4332. foundZone = zone_list.GetZoneByInstance(&zone_details, 0, zoneID);
  4333. }
  4334. else {
  4335. peer_manager.setZonePeerDataSelf(&zone_details, std::string(instance_zone->GetZoneFile()), std::string(instance_zone->GetZoneName()),
  4336. instance_zone->GetZoneID(), instance_zone->GetInstanceID(), instance_zone->GetSafeX(), instance_zone->GetSafeY(),
  4337. instance_zone->GetSafeZ(), instance_zone->GetSafeHeading(), instance_zone->GetZoneLockState(),
  4338. instance_zone->GetMinimumStatus(), instance_zone->GetMinimumLevel(), instance_zone->GetMaximumLevel(),
  4339. instance_zone->GetMinimumVersion(), instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime(),
  4340. instance_zone->GetInstanceType(), instance_zone->NumPlayers(), instance_zone);
  4341. }
  4342. }
  4343. else {
  4344. foundZone = zone_list.GetZoneByInstance(&zone_details, 0, zoneID);
  4345. }
  4346. break;
  4347. }
  4348. case PERSONAL_HOUSE_INSTANCE:
  4349. case GUILD_HOUSE_INSTANCE:
  4350. {
  4351. // Because of the way housing works (need to load a specific instance id supplied in a packet) we can't
  4352. // use this function without some rework, so it will all be handled in Client::HandlePacket()
  4353. // with the OP_EnterHouseMsg opcode
  4354. break;
  4355. }
  4356. case QUEST_INSTANCE:
  4357. {
  4358. foundZone = zone_list.GetZoneByInstance(&zone_details, 0, zoneID);
  4359. break;
  4360. /*
  4361. 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`;
  4362. */
  4363. }
  4364. default:
  4365. {
  4366. // NONE
  4367. }
  4368. }
  4369. }
  4370. if (foundZone)
  4371. Zone(&zone_details, (ZoneServer*)zone_details.zonePtr, zone_coords_valid);
  4372. }
  4373. return foundZone;
  4374. }
  4375. bool Client::GotoSpawn(const char* search_name, bool forceTarget) {
  4376. Spawn* target = 0;
  4377. if (search_name || GetPlayer()->GetTarget()) {
  4378. Client* search_client = 0;
  4379. if (search_name) {
  4380. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  4381. if (!target) {
  4382. search_client = zone_list.GetClientByCharName(search_name);
  4383. if (search_client)
  4384. target = search_client->GetPlayer();
  4385. }
  4386. if (target)
  4387. GetPlayer()->SetTarget(target);
  4388. }
  4389. else
  4390. target = GetPlayer()->GetTarget();
  4391. float y = (target != nullptr) ? target->GetY() : 0.0f;
  4392. if (target && target->GetMap() != GetPlayer()->GetMap()) {
  4393. auto loc = glm::vec3(target->GetX(), target->GetZ(), target->GetY());
  4394. y = GetPlayer()->FindBestZ(loc, nullptr);
  4395. }
  4396. if (target && target != GetPlayer()) {
  4397. GetPlayer()->SetX(target->GetX());
  4398. GetPlayer()->SetY(y);
  4399. GetPlayer()->SetZ(target->GetZ());
  4400. GetPlayer()->SetHeading(target->GetHeading());
  4401. GetPlayer()->SetLocation(target->GetLocation());
  4402. Message(CHANNEL_COLOR_YELLOW, "Warping to '%s'", target->GetName());
  4403. }
  4404. else if (target)
  4405. Message(CHANNEL_COLOR_RED, "Error: You cannot goto yourself!");
  4406. if (search_client && search_client->GetCurrentZone() != GetCurrentZone())
  4407. Zone(search_client->GetCurrentZone()->GetZoneName(), false);
  4408. else if (target) {
  4409. EQ2Packet* app = GetPlayer()->Move(target->GetX(), y, target->GetZ(), GetVersion(), (target->GetHeading() + 180.0f));
  4410. if (app)
  4411. QueuePacket(app);
  4412. }
  4413. }
  4414. if (!target)
  4415. return false;
  4416. else
  4417. return true;
  4418. }
  4419. bool Client::CheckZoneAccess(const char* zoneName) {
  4420. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone access check for %s (%u), client: %u", zoneName, database.GetZoneID(zoneName), GetVersion());
  4421. bool zoneFound = false;
  4422. ZoneChangeDetails zone_details;
  4423. if (zoneFound = zone_list.GetZone(&zone_details, 0, std::string(zoneName), false, false, false)) {
  4424. // JA: implemented /zone lock|unlock commands (2012.07.28)
  4425. if (zone_details.lockState)
  4426. {
  4427. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone currently LOCKED: '%s' (%ul)", zoneName, zone_details.zoneId);
  4428. Message(CHANNEL_COLOR_RED, "This zone is locked, and you don't have the key! (%s).", zoneName);
  4429. return false;
  4430. }
  4431. }
  4432. sint16 zoneMinStatus = 0;
  4433. int16 zoneMinLevel = 0;
  4434. int16 zoneMaxLevel = 0;
  4435. int16 zoneMinVersion = 0;
  4436. if (!zoneFound)
  4437. {
  4438. LogWrite(CCLIENT__DEBUG, 0, "Client", "Grabbing zone requirements for %s", zoneName);
  4439. bool success = database.GetZoneRequirements(zoneName, &zoneMinStatus, &zoneMinLevel, &zoneMaxLevel, &zoneMinVersion);
  4440. if (!success) { // couldn't even find the zone, this shouldn't happen though..
  4441. return true;
  4442. }
  4443. }
  4444. else
  4445. {
  4446. zoneMinStatus = zone_details.minStatus;
  4447. zoneMinLevel = zone_details.minLevel;
  4448. zoneMaxLevel = zone_details.maxLevel;
  4449. zoneMinVersion = zone_details.minVersion;
  4450. }
  4451. LogWrite(CCLIENT__DEBUG, 0, "Client", "Access Requirements: status %i, level %i - %i, req >= %i version", zoneMinStatus, zoneMinLevel, zoneMaxLevel, zoneMinVersion);
  4452. // use ZoneLevelOverrideStatus in both min_level and max_level checks
  4453. sint16 ZoneLevelOverrideStatus = rule_manager.GetZoneRule(GetCurrentZoneID(), R_Zone, MinZoneLevelOverrideStatus)->GetSInt16();
  4454. if ((zoneMinVersion > 0) && (GetVersion() < zoneMinVersion))
  4455. {
  4456. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinVersion of %i challenge...", zoneMinVersion);
  4457. Message(CHANNEL_COLOR_RED, "You do not have the required expansion pack to enter here (%s).", database.GetExpansionIDByVersion(zoneMinVersion).c_str());
  4458. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client denied access to zone '%s' (version req: %i)", zoneName, zoneMinVersion);
  4459. return false;
  4460. }
  4461. if ((zoneMinLevel > 1) && (player->GetLevel() < zoneMinLevel))
  4462. {
  4463. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  4464. {
  4465. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  4466. Message(CHANNEL_COLOR_RED, "Your level is too low to enter here (%s)", zoneMinLevel);
  4467. return false;
  4468. }
  4469. }
  4470. if ((zoneMaxLevel > 1) && (player->GetLevel() > zoneMaxLevel))
  4471. {
  4472. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  4473. {
  4474. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  4475. Message(CHANNEL_COLOR_RED, "Your level is too high to enter here (%s)", zoneMaxLevel);
  4476. return false;
  4477. }
  4478. }
  4479. if ((zoneMinStatus > 0) && (GetAdminStatus() < zoneMinStatus))
  4480. {
  4481. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinStatus of %i challenge...", zoneMinStatus);
  4482. sint16 ZoneAccessOverrideStatus = rule_manager.GetZoneRule(GetCurrentZoneID(), R_Zone, MinZoneAccessOverrideStatus)->GetSInt16();
  4483. if (ZoneAccessOverrideStatus && ZoneAccessOverrideStatus > GetAdminStatus())
  4484. {
  4485. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (status req: %i)", zoneName, GetAdminStatus());
  4486. Message(CHANNEL_COLOR_RED, "You do not have permission to enter here (%i).", zoneMinStatus);
  4487. return false;
  4488. }
  4489. }
  4490. return true;
  4491. }
  4492. void Client::Zone(int32 instanceid, bool set_coords, bool byInstanceID, bool is_spell) {
  4493. ZoneChangeDetails zone_details;
  4494. if (zone_list.GetZoneByInstance(&zone_details, instanceid, 0)) {
  4495. Zone(&zone_details, (ZoneServer*)zone_details.zonePtr, set_coords, is_spell);
  4496. }
  4497. }
  4498. void Client::Zone(ZoneChangeDetails* new_zone, ZoneServer* opt_zone, bool set_coords, bool is_spell) {
  4499. if (GetVersion() == 373 && GetAdminStatus() == 0) {
  4500. if (new_zone->zoneFileName.find("boat_06p_tutorial02") == std::string::npos && new_zone->zoneFileName.find("tutorial_island02") == std::string::npos
  4501. && new_zone->zoneFileName.find("tutorial_island02_epic") == std::string::npos) { // accounts for 01 and 02 zones
  4502. SimpleMessage(CHANNEL_COLOR_RED, "This client does not currently support beyond the boat tutorial (farjourneyfreeport) or island of refuge (islerefuge1)");
  4503. return;
  4504. }
  4505. }
  4506. else if (GetVersion() < 546 && GetVersion() > 561) {
  4507. if (new_zone->zoneFileName.find("design_path_script") != std::string::npos) {
  4508. SimpleMessage(CHANNEL_COLOR_RED, "This zone is only available for KoS and earlier clients.");
  4509. return;
  4510. }
  4511. }
  4512. if (client_zoning) {
  4513. return;
  4514. }
  4515. client_zoning = true;
  4516. zoning_id = new_zone->zoneId;
  4517. zoning_instance_id = new_zone->instanceId;
  4518. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting player Resurrecting to 'true'", __FUNCTION__);
  4519. player->SetResurrecting(true);
  4520. if (set_coords)
  4521. {
  4522. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Zoning player to coordinates x: %2f, y: %2f, z: %2f, heading: %2f in zone '%s'...",
  4523. __FUNCTION__,
  4524. new_zone->safeX,
  4525. new_zone->safeY,
  4526. new_zone->safeZ,
  4527. new_zone->safeHeading,
  4528. new_zone->zoneName.c_str()
  4529. );
  4530. player->SetX(new_zone->safeX);
  4531. player->SetY(new_zone->safeY);
  4532. player->SetZ(new_zone->safeZ);
  4533. player->SetHeading(new_zone->safeHeading);
  4534. SetZoningCoords(new_zone->safeX, new_zone->safeY,
  4535. new_zone->safeZ, new_zone->safeHeading);
  4536. }
  4537. else {
  4538. ResetZoningCoords();
  4539. }
  4540. Save();
  4541. ResetSendMail();
  4542. // Remove players pet from zone if there is one
  4543. ((Entity*)player)->DismissAllPets();
  4544. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from current zone...", __FUNCTION__);
  4545. GetCurrentZone()->RemoveSpawn(player, false, true, true, true, !is_spell);
  4546. GetPlayer()->DeleteSpellEffects(true);
  4547. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting zone to '%s'...", __FUNCTION__, new_zone->zoneName.c_str());
  4548. SetZoningDestination(opt_zone);
  4549. SetCurrentZone(opt_zone);
  4550. if (player->GetGroupMemberInfo())
  4551. {
  4552. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Player in group, updating group info...", __FUNCTION__);
  4553. player->UpdateGroupMemberInfo();
  4554. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id, this);
  4555. }
  4556. // block out the member info for the group
  4557. TempRemoveGroup();
  4558. UpdateTimeStampFlag(ZONE_UPDATE_FLAG);
  4559. const char* new_zone_ip = 0;
  4560. if (IsPrivateAddress(this->GetIP()) && new_zone->peerInternalWorldAddress.length() > 0)
  4561. new_zone_ip = new_zone->peerInternalWorldAddress.c_str();
  4562. else
  4563. new_zone_ip = new_zone->peerWorldAddress.c_str();
  4564. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: New Zone IP '%s'...", __FUNCTION__, new_zone_ip);
  4565. int32 key = static_cast<unsigned int>(MakeRandomFloat(0.01, 1.0) * UINT32_MAX);
  4566. new_zone->zoneKey = key;
  4567. new_zone->authDispatchedTime = Timer::GetUnixTimeStamp();
  4568. zoning_details = ZoneChangeDetails(new_zone);
  4569. client_zoning_details_set = true;
  4570. if (new_zone->peerId.length() > 0 && new_zone->peerId != "self") {
  4571. if (new_zone->peerAuthorized) {
  4572. LogWrite(PEERING__INFO, 0, "Peering", "%s: Peer %s authorized us to zone...", __FUNCTION__, new_zone->peerId.c_str());
  4573. }
  4574. else {
  4575. boost::property_tree::ptree root;
  4576. struct in_addr in;
  4577. in.s_addr = GetIP();
  4578. root.put("account_id", std::to_string(GetAccountID()));
  4579. root.put("character_name", std::string(player->GetName()));
  4580. root.put("zone_name", new_zone->zoneName);
  4581. root.put("zone_id", new_zone->zoneId);
  4582. root.put("instance_id", new_zone->instanceId);
  4583. root.put("login_key", std::to_string(key));
  4584. root.put("client_ip", std::string(inet_ntoa(in)));
  4585. root.put("first_login", false);
  4586. std::ostringstream jsonStream;
  4587. boost::property_tree::write_json(jsonStream, root);
  4588. std::string jsonPayload = jsonStream.str();
  4589. LogWrite(PEERING__INFO, 0, "Peering", "%s: Sending AddCharAuth for %s to peer %s:%u for zone %s", __FUNCTION__, player->GetName(), new_zone->peerWebAddress.c_str(), new_zone->peerWebPort, new_zone->zoneName.c_str());
  4590. peer_https_pool.sendPostRequestToPeerAsync(new_zone->peerId, new_zone->peerWebAddress, std::to_string(new_zone->peerWebPort), "/addcharauth", jsonPayload);
  4591. }
  4592. }
  4593. else {
  4594. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending to zone_auth.AddAuth...", __FUNCTION__);
  4595. zone_auth.AddAuth(new ZoneAuthRequest(GetAccountID(), player->GetName(), key));
  4596. new_zone->peerAuthorized = true; // local, we can bypass (should technically already be true)
  4597. zoning_details = ZoneChangeDetails(new_zone);
  4598. }
  4599. if (new_zone->peerAuthorized) {
  4600. ApproveZone();
  4601. }
  4602. }
  4603. void Client::ApproveZone() {
  4604. if (!client_zoning_details_set) {
  4605. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: client zoning details not set to zone player %s...", __FUNCTION__, player->GetName());
  4606. return;
  4607. }
  4608. zoning_details.zoningPastAuth = true;
  4609. zoning_details.peerAuthorized = true;
  4610. const char* new_zone_ip = 0;
  4611. if (IsPrivateAddress(this->GetIP()) && zoning_details.peerInternalWorldAddress.length() > 0)
  4612. new_zone_ip = zoning_details.peerInternalWorldAddress.c_str();
  4613. else
  4614. new_zone_ip = zoning_details.peerWorldAddress.c_str();
  4615. LogWrite(CCLIENT__INFO, 0, "Client", "%s: Sending ZoneChangeMsg %s:%u with key %u...", player->GetName(), (char*)new_zone_ip, zoning_details.peerWorldPort, zoning_details.zoneKey);
  4616. ClientPacketFunctions::SendZoneChange(this, (char*)new_zone_ip, zoning_details.peerWorldPort, zoning_details.zoneKey);
  4617. if (version > 373) {
  4618. PacketStruct* packet = configReader.getStruct("WS_CancelMoveObjectMode", version);
  4619. if (packet)
  4620. {
  4621. QueuePacket(packet->serialize());
  4622. safe_delete(packet);
  4623. }
  4624. }
  4625. }
  4626. void Client::Zone(const char* new_zone, bool set_coords, bool is_spell)
  4627. {
  4628. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request to '%s'", new_zone);
  4629. ZoneChangeDetails zone_details;
  4630. int32 zone_id = database.GetZoneID(new_zone);
  4631. std::string camelCaseName = database.GetZoneName(zone_id);
  4632. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zone_id);
  4633. if ((data && zone_list.GetZoneByInstance(&zone_details, data->instance_id, zone_id)) || zone_list.GetZone(&zone_details, 0, camelCaseName)) {
  4634. Zone(&zone_details, (ZoneServer*)zone_details.zonePtr, set_coords, is_spell);
  4635. }
  4636. }
  4637. float Client::DistanceFrom(Client* client) {
  4638. float ret = 0;
  4639. if (client && client != this) {
  4640. ret = pow(player->GetX() - client->player->GetX(), 2) + pow(player->GetY() - client->player->GetY(), 2) + pow(player->GetZ() - client->player->GetZ(), 2);
  4641. ret = sqrt(ret);
  4642. }
  4643. return ret;
  4644. }
  4645. void Client::DetermineCharacterUpdates() {
  4646. ServerPacket* outpack = new ServerPacket(ServerOP_BasicCharUpdate, sizeof(CharDataUpdate_Struct));
  4647. CharDataUpdate_Struct* cdu = (CharDataUpdate_Struct*)outpack->pBuffer;
  4648. cdu->account_id = GetAccountID();
  4649. cdu->char_id = GetCharacterID();
  4650. int32 timestamp = Timer::GetUnixTimeStamp();
  4651. int8 flag = GetTimeStampFlag();
  4652. if (flag & LEVEL_UPDATE_FLAG)
  4653. {
  4654. cdu->update_field = LEVEL_UPDATE_FLAG;
  4655. cdu->update_data = player->GetLevel();
  4656. loginserver.SendPacket(outpack);
  4657. }
  4658. //if(flag&CLASS_UPDATE_FLAG && player->GetLevel() >= 20)// Perseverance only
  4659. if (flag & CLASS_UPDATE_FLAG)
  4660. {
  4661. cdu->update_field = CLASS_UPDATE_FLAG;
  4662. cdu->update_data = player->GetAdventureClass();
  4663. loginserver.SendPacket(outpack);
  4664. }
  4665. if (flag & GENDER_UPDATE_FLAG)
  4666. {
  4667. cdu->update_field = GENDER_UPDATE_FLAG;
  4668. cdu->update_data = player->GetGender();
  4669. loginserver.SendPacket(outpack);
  4670. }
  4671. if (flag & DELETE_UPDATE_FLAG) {
  4672. LogWrite(MISC__TODO, 1, "TODO", "Delete update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  4673. }
  4674. safe_delete(outpack); // Zone, armor and name use a different structure
  4675. if (flag & RACE_UPDATE_FLAG)
  4676. {
  4677. outpack = new ServerPacket(ServerOP_RaceUpdate, sizeof(RaceUpdate_Struct));
  4678. RaceUpdate_Struct* ru = (RaceUpdate_Struct*)outpack->pBuffer;
  4679. ru->account_id = GetAccountID();
  4680. ru->char_id = GetCharacterID();
  4681. ru->race = player->GetRace();
  4682. ru->model_type = player->GetModelType();
  4683. loginserver.SendPacket(outpack);
  4684. safe_delete(outpack);
  4685. }
  4686. if (flag & ZONE_UPDATE_FLAG) {
  4687. ServerPacket* outpack = new ServerPacket(ServerOP_ZoneUpdate, CHARZONESTRUCT_MAXSIZE);
  4688. memset(outpack->pBuffer, 0, CHARZONESTRUCT_MAXSIZE);
  4689. CharZoneUpdate_Struct* czu = (CharZoneUpdate_Struct*)outpack->pBuffer;
  4690. czu->account_id = GetAccountID();
  4691. czu->char_id = GetCharacterID();
  4692. czu->zone_id = GetCurrentZone()->GetZoneID();
  4693. const char* zone_file = GetCurrentZone()->GetZoneFile();
  4694. czu->zone_length = strlen(zone_file);
  4695. if (czu->zone_length > 64)
  4696. czu->zone_length = 64;
  4697. strncpy(czu->new_zone, zone_file, czu->zone_length);
  4698. loginserver.SendPacket(outpack);
  4699. safe_delete(outpack);
  4700. }
  4701. if (flag & ARMOR_UPDATE_FLAG) {
  4702. LogWrite(MISC__TODO, 1, "TODO", "Armor update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  4703. }
  4704. if (flag & NAME_UPDATE_FLAG) {
  4705. LogWrite(MISC__TODO, 1, "TODO", "Name update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  4706. }
  4707. database.UpdateCharacterTimeStamp(GetAccountID(), GetCharacterID(), timestamp);
  4708. }
  4709. void Client::Save() {
  4710. if (GetCharacterID() == 0 || IsSaveDisabled())
  4711. return;
  4712. if (current_zone) {
  4713. DetermineCharacterUpdates();
  4714. UpdateCharacterInstances();
  4715. this->SetLastSavedTimeStamp(Timer::GetCurrentTime2());
  4716. database.Save(this);
  4717. if (GetPlayer()->UpdateQuickbarNeeded()) {
  4718. database.SaveQuickBar(GetCharacterID(), GetPlayer()->GetQuickbar());
  4719. GetPlayer()->ResetQuickbarNeeded();
  4720. }
  4721. database.SaveItems(this);
  4722. database.SaveBuyBacks(this);
  4723. GetPlayer()->SaveHistory();
  4724. GetPlayer()->SaveLUAHistory();
  4725. MSaveSpellStateMutex.lock();
  4726. GetPlayer()->SaveSpellEffects();
  4727. MSaveSpellStateMutex.unlock();
  4728. }
  4729. }
  4730. void Client::UpdateCharacterInstances() {
  4731. if (GetPlayer() != NULL)
  4732. GetPlayer()->GetCharacterInstances()->ProcessInstanceTimers(GetPlayer());
  4733. /*if ( GetPlayer() != NULL )
  4734. {
  4735. // determine the last timestamp then get a new one, determine the difference in the timestamp
  4736. // to use for applying the update to each instances timer
  4737. int32 lastSaveTS = GetLastSavedTimeStamp();
  4738. int32 newSaveTS = Timer::GetUnixTimeStamp();
  4739. int32 diffTS = newSaveTS - lastSaveTS;
  4740. // update instance timers
  4741. GetPlayer()->GetCharacterInstances().ProcessInstanceTimers(GetPlayer(),diffTS);
  4742. // update with the new timestamp and save the db
  4743. this->SetLastSavedTimeStamp(newSaveTS);
  4744. }*/
  4745. }
  4746. void Client::HandleVerbRequest(EQApplicationPacket* app) {
  4747. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsRequest", GetVersion());
  4748. if (packet) {
  4749. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  4750. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  4751. PacketStruct* out = configReader.getStruct("WS_EntityVerbsResponse", GetVersion());
  4752. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(spawn_id);
  4753. vector<EntityCommand*> commands;
  4754. vector<EntityCommand*> delete_commands;
  4755. if (out && spawn) {
  4756. for (int32 i = 0; i < spawn->primary_command_list.size(); i++)
  4757. {
  4758. // default is a deny list not allow, only allow if on the iterator list and itr second is not false (deny)
  4759. if (!spawn->primary_command_list[i]->default_allow_list)
  4760. {
  4761. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  4762. if (itr == spawn->primary_command_list[i]->allow_or_deny.end() || !itr->second)
  4763. continue;
  4764. }
  4765. else
  4766. {
  4767. // default is allow list, only deny if added to the list as deny (false itr second)
  4768. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  4769. if (itr != spawn->primary_command_list[i]->allow_or_deny.end() && !itr->second)
  4770. continue;
  4771. }
  4772. commands.push_back(spawn->primary_command_list[i]);
  4773. }
  4774. for (int32 i = 0; i < spawn->secondary_command_list.size(); i++)
  4775. commands.push_back(spawn->secondary_command_list[i]);
  4776. if (spawn->IsPlayer()) {
  4777. if (player->IsFriend(spawn->GetName()))
  4778. delete_commands.push_back(player->CreateEntityCommand("remove from friends list", 10000, "friend_remove", "", 0, 0));
  4779. else
  4780. delete_commands.push_back(player->CreateEntityCommand("add to friends list", 10000, "friend_add", "", 0, 0));
  4781. if (player->IsIgnored(spawn->GetName()))
  4782. delete_commands.push_back(player->CreateEntityCommand("remove from ignore list", 10000, "ignore_remove", "", 0, 0));
  4783. else
  4784. {
  4785. delete_commands.push_back(player->CreateEntityCommand("add to ignore list", 10000, "ignore_add", "", 0, 0));
  4786. delete_commands.push_back(player->CreateEntityCommand("Trade", 10, "start_trade", "", 0, 0));
  4787. }
  4788. if (((Player*)spawn)->GetGroupMemberInfo()) {
  4789. if (player->IsGroupMember((Player*)spawn) && player->GetGroupMemberInfo()->leader) { //group leader
  4790. delete_commands.push_back(player->CreateEntityCommand("kick from group", 10000, "kickfromgroup", "", 0, 0));
  4791. delete_commands.push_back(player->CreateEntityCommand("make group leader", 10000, "makeleader", "", 0, 0));
  4792. }
  4793. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4794. int32 spawn_group_id = ((Player*)spawn)->GetGroupMemberInfo()->group_id;
  4795. PlayerGroup* spawn_group = world.GetGroupManager()->GetGroup(spawn_group_id);
  4796. int32 player_group_id = player->GetGroupMemberInfo() ? player->GetGroupMemberInfo()->group_id : 0;
  4797. PlayerGroup* player_group = nullptr;
  4798. if (player_group_id)
  4799. player_group = world.GetGroupManager()->GetGroup(player_group_id);
  4800. if (spawn_group && !player->IsGroupMember((Player*)spawn) && !spawn_group->IsGroupRaid() && player_group && player->GetGroupMemberInfo()->leader
  4801. && (!player_group->IsInRaidGroup(spawn_group_id) || player_group->IsInRaidGroup(player_group_id, true))) {
  4802. delete_commands.push_back(player->CreateEntityCommand("invite to raid", 10000, "raidinvite", "", 0, 0));
  4803. }
  4804. else if (spawn_group && player_group && player_group->IsInRaidGroup(player_group_id, true) && player->GetGroupMemberInfo()->leader && player_group->IsInRaidGroup(spawn_group_id)) {
  4805. if (((Player*)spawn)->GetGroupMemberInfo()->is_raid_looter) {
  4806. delete_commands.push_back(player->CreateEntityCommand("remove looter", 10000, "raid_looter", "", 0, 0));
  4807. }
  4808. else {
  4809. delete_commands.push_back(player->CreateEntityCommand("add looter", 10000, "raid_looter", "", 0, 0));
  4810. }
  4811. delete_commands.push_back(player->CreateEntityCommand("disband from raid", 10000, "raiddisband", "", 0, 0));
  4812. }
  4813. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4814. if (spawn->IsPlayer() && player->GetGroupMemberInfo() && !player->GetGroupMemberInfo()->mentor_target_char_id && player_group_id == spawn_group_id)
  4815. delete_commands.push_back(player->CreateEntityCommand("Mentor", 10000, "mentor", "", 0, 0));
  4816. else if (spawn->IsPlayer() && player->GetGroupMemberInfo() && player->GetGroupMemberInfo()->mentor_target_char_id == ((Player*)spawn)->GetCharacterID())
  4817. delete_commands.push_back(player->CreateEntityCommand("Stop Mentoring", 10000, "unmentor", "", 0, 0));
  4818. }
  4819. else if (!player->GetGroupMemberInfo() || (player->GetGroupMemberInfo()->leader && world.GetGroupManager()->GetGroupSize(player->GetGroupMemberInfo()->group_id) < 6))
  4820. delete_commands.push_back(player->CreateEntityCommand("invite to group", 10000, "invite", "", 0, 0));
  4821. commands.insert(commands.end(), delete_commands.begin(), delete_commands.end());
  4822. }
  4823. out->setDataByName("spawn_id", spawn_id);
  4824. out->setArrayLengthByName("num_verbs", commands.size());
  4825. for (int32 i = 0; i < commands.size(); i++) {
  4826. out->setArrayDataByName("command", commands[i]->command.c_str(), i);
  4827. out->setArrayDataByName("distance", commands[i]->distance, i);
  4828. if (commands[i]->error_text.length() == 0)
  4829. out->setArrayAddToPacketByName("error", false, i);
  4830. else {
  4831. out->setArrayDataByName("display_error", 1, i);
  4832. out->setArrayDataByName("error", commands[i]->error_text.c_str(), i);
  4833. }
  4834. out->setArrayDataByName("display_text", commands[i]->name.c_str(), i);
  4835. }
  4836. EQ2Packet* outapp = out->serialize();
  4837. //DumpPacket(outapp);
  4838. QueuePacket(outapp);
  4839. safe_delete(out);
  4840. for (int32 i = 0; i < delete_commands.size(); i++) {
  4841. safe_delete(delete_commands[i]);
  4842. }
  4843. }
  4844. }
  4845. safe_delete(packet);
  4846. }
  4847. }
  4848. void Client::SkillChanged(Skill* skill, int16 previous_value, int16 new_value) {
  4849. if (previous_value != new_value) {
  4850. 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);
  4851. char tmp[200] = { 0 };
  4852. 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);
  4853. SendPopupMessage(6, tmp, new_value > previous_value ? "skill_up" : "skill_down", 2.75f, 0xFF, 0xFF, 0xFF);
  4854. }
  4855. }
  4856. void Client::SendPopupMessage(int8 unknown, const char* text, const char* type, float size, int8 red, int8 green, int8 blue)
  4857. {
  4858. /* JA notes on the unknown:
  4859. 2 = ding glimmer
  4860. 16 = Achievement Unlocked
  4861. 6 no longer does anything
  4862. */
  4863. PacketStruct* packet = configReader.getStruct("WS_OnScreenMsg", GetVersion());
  4864. if (packet) {
  4865. packet->setDataByName("unknown", unknown);
  4866. packet->setMediumStringByName("text", text);
  4867. if (type && strlen(type) > 0)
  4868. packet->setMediumStringByName("message_type", type);
  4869. packet->setDataByName("size", size);
  4870. packet->setDataByName("red", red);
  4871. packet->setDataByName("green", green);
  4872. packet->setDataByName("blue", blue);
  4873. QueuePacket(packet->serialize());
  4874. safe_delete(packet);
  4875. }
  4876. }
  4877. void Client::ChangeLevel(int16 old_level, int16 new_level) {
  4878. if (new_level < 1) {
  4879. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  4880. return;
  4881. }
  4882. if (player->GetLevel() != new_level) {
  4883. player->SetLevel(new_level);
  4884. if (player->GetGroupMemberInfo()) {
  4885. player->UpdateGroupMemberInfo();
  4886. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  4887. }
  4888. }
  4889. if (new_level > old_level) {
  4890. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_ADVENTURE, new_level, player->GetAdventureClass());
  4891. }
  4892. if (player->GetPet()) {
  4893. NPC* pet = (NPC*)player->GetPet();
  4894. if (pet->GetMaxPetLevel() == 0 || new_level <= pet->GetMaxPetLevel()) {
  4895. pet->SetLevel(new_level);
  4896. pet->UpdateWeapons();
  4897. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4898. if (command_packet) {
  4899. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(pet));
  4900. command_packet->setDataByName("anim_type", 1753);
  4901. QueuePacket(command_packet->serialize());
  4902. safe_delete(command_packet);
  4903. }
  4904. }
  4905. }
  4906. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  4907. if (level_update) {
  4908. level_update->setDataByName("old_level", old_level);
  4909. level_update->setDataByName("new_level", new_level);
  4910. QueuePacket(level_update->serialize());
  4911. safe_delete(level_update);
  4912. GetCurrentZone()->StartZoneSpawnsForLevelThread(this);
  4913. GetCurrentZone()->SendCastSpellPacket(322, player, player); //send level up spell effect
  4914. //GetCurrentZone()->SendAllSpawnsForLevelChange(this);
  4915. }
  4916. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4917. if (command_packet) {
  4918. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  4919. command_packet->setDataByName("anim_type", 1753);
  4920. QueuePacket(command_packet->serialize());
  4921. safe_delete(command_packet);
  4922. }
  4923. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && new_level >= rule_manager.GetZoneRule(GetCurrentZoneID(), R_Player, MinLastNameLevel)->GetInt8())
  4924. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  4925. SendNewAdventureSpells();
  4926. GetPlayer()->GetInfoStruct()->set_level(new_level);
  4927. GetPlayer()->UpdateWeapons();
  4928. // GetPlayer()->SetLevel(new_level);
  4929. 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__);
  4930. GetPlayer()->CalculatePlayerHPPower();
  4931. GetPlayer()->CalculateBonuses();
  4932. GetPlayer()->SetHP(GetPlayer()->GetTotalHP());
  4933. GetPlayer()->SetPower(GetPlayer()->GetTotalPower());
  4934. /*InfoStruct* info = player->GetInfoStruct();
  4935. info->set_agi_base(new_level * 2 + 15);
  4936. info->set_intel_base(new_level * 2 + 15);
  4937. info->set_wis_base(new_level * 2 + 15);
  4938. info->set_str_base(new_level * 2 + 15);
  4939. info->set_sta_base(new_level * 2 + 15);
  4940. info->set_cold_base((int16)(new_level * 1.5 + 10));
  4941. info->set_heat_base((int16)(new_level * 1.5 + 10));
  4942. info->set_disease_base((int16)(new_level * 1.5 + 10));
  4943. info->set_mental_base((int16)(new_level * 1.5 + 10));
  4944. info->set_magic_base((int16)(new_level * 1.5 + 10));
  4945. info->set_divine_base((int16)(new_level * 1.5 + 10));
  4946. info->set_poison_base((int16)(new_level * 1.5 + 10));
  4947. GetPlayer()->GetInfoStruct()->set_poison_base((int16)(new_level * 1.5 + 10));*/
  4948. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  4949. GetPlayer()->SetCharSheetChanged(true);
  4950. Message(CHANNEL_REWARD, "You are now level %i!", new_level);
  4951. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  4952. int16 new_skill_cap = 5 * new_level;
  4953. PlayerSkillList* player_skills = player->GetSkills();
  4954. player_skills->SetSkillCapsByType(SKILL_TYPE_ARMOR, new_skill_cap);
  4955. player_skills->SetSkillCapsByType(SKILL_TYPE_SHIELD, new_skill_cap);
  4956. if (rule_manager.GetZoneRule(GetCurrentZoneID(), R_Player, AutoSkillUpBaseSkills)->GetBool()) {
  4957. //SKILL_TYPE_ARMOR/SKILL_TYPE_SHIELD always has the same current / max values
  4958. player_skills->SetSkillValuesByType(SKILL_TYPE_ARMOR, new_skill_cap, false);
  4959. player_skills->SetSkillValuesByType(SKILL_TYPE_SHIELD, new_skill_cap, false);
  4960. }
  4961. player_skills->SetSkillCapsByType(SKILL_TYPE_CLASS, new_skill_cap);
  4962. player_skills->SetSkillCapsByType(SKILL_TYPE_WEAPON, new_skill_cap);
  4963. if (rule_manager.GetZoneRule(GetCurrentZoneID(), R_Player, AutoSkillUpBaseSkills)->GetBool()) {
  4964. //SKILL_TYPE_CLASS/SKILL_TYPE_WEAPON always has the same current/max values
  4965. player_skills->SetSkillValuesByType(SKILL_TYPE_CLASS, new_skill_cap, false);
  4966. player_skills->SetSkillValuesByType(SKILL_TYPE_WEAPON, new_skill_cap, false);
  4967. }
  4968. player_skills->SetSkillCapsByType(SKILL_TYPE_COMBAT, new_skill_cap);
  4969. player_skills->SetSkillCapsByType(SKILL_TYPE_GENERAL, new_skill_cap);
  4970. player_skills->SetSkillCapsByType(SKILL_TYPE_SPELLCASTING, new_skill_cap);
  4971. player_skills->SetSkillCapsByType(SKILL_TYPE_AVOIDANCE, new_skill_cap);
  4972. player_skills->SetSkillCapsByType(SKILL_TYPE_WEAPONRY, new_skill_cap);
  4973. if (new_level > player->GetTSLevel())
  4974. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, new_skill_cap);
  4975. //SKILL_ID_DUALWIELD, SKILL_ID_FISTS, SKILL_ID_DESTROYING, and SKILL_ID_MAGIC_AFFINITY always have the current_val equal to max_val
  4976. if (player_skills->HasSkill(SKILL_ID_DUALWIELD))
  4977. player_skills->SetSkill(SKILL_ID_DUALWIELD, new_skill_cap);
  4978. if (player_skills->HasSkill(SKILL_ID_FISTS))
  4979. player_skills->SetSkill(SKILL_ID_FISTS, new_skill_cap);
  4980. if (player_skills->HasSkill(SKILL_ID_DESTROYING))
  4981. player_skills->SetSkill(SKILL_ID_DESTROYING, new_skill_cap);
  4982. if (player_skills->HasSkill(SKILL_ID_MAGIC_AFFINITY))
  4983. player_skills->SetSkill(SKILL_ID_MAGIC_AFFINITY, new_skill_cap);
  4984. Guild* guild = GetPlayer()->GetGuild();
  4985. if (guild) {
  4986. int8 event_type = 0;
  4987. if (new_level < 10)
  4988. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_1_10;
  4989. else if (new_level == 10)
  4990. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_10;
  4991. else if (new_level >= 11 && new_level < 20)
  4992. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_11_20;
  4993. else if (new_level == 20)
  4994. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_20;
  4995. else if (new_level >= 21 && new_level < 30)
  4996. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_21_30;
  4997. else if (new_level == 30)
  4998. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_30;
  4999. else if (new_level >= 31 && new_level < 40)
  5000. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_31_40;
  5001. else if (new_level == 40)
  5002. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_40;
  5003. else if (new_level >= 41 && new_level < 50)
  5004. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_41_50;
  5005. else if (new_level == 50)
  5006. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_50;
  5007. else if (new_level >= 51 && new_level < 60)
  5008. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_51_60;
  5009. else if (new_level == 60)
  5010. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_60;
  5011. else if (new_level >= 61 && new_level < 70)
  5012. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_61_70;
  5013. else if (new_level == 70)
  5014. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_70;
  5015. else if (new_level >= 71 && new_level < 80)
  5016. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_71_80;
  5017. else if (new_level == 80)
  5018. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_80;
  5019. 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());
  5020. 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());
  5021. guild->UpdateGuildMemberInfo(GetPlayer());
  5022. guild->SendGuildMember(GetPlayer());
  5023. guild->SendGuildMemberList();
  5024. }
  5025. // Need to send the trait list every time the players level changes
  5026. // Also need to force the char sheet update or else there can be a large delay from when you level
  5027. // to when you are actually able to select traits.
  5028. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  5029. GetPlayer()->need_trait_update = true;
  5030. if (version > 561) {
  5031. QueuePacket(master_trait_list.GetTraitListPacket(this));
  5032. master_aa_list.DisplayAA(this, 0, 0);
  5033. }
  5034. else
  5035. master_trait_list.ChooseNextTrait(this);
  5036. if (GetPlayer()->SpawnedBots.size() > 0) {
  5037. map<int32, int32>::iterator itr;
  5038. for (itr = GetPlayer()->SpawnedBots.begin(); itr != GetPlayer()->SpawnedBots.end(); itr++) {
  5039. Spawn* bot = GetCurrentZone()->GetSpawnByID(itr->second);
  5040. if (bot && bot->IsBot())
  5041. ((Bot*)bot)->ChangeLevel(old_level, new_level);
  5042. }
  5043. }
  5044. if (GetPlayer()->GetHP() < GetPlayer()->GetTotalHP() || GetPlayer()->GetPower() < GetPlayer()->GetTotalPower())
  5045. GetPlayer()->GetZone()->AddDamagedSpawn(GetPlayer());
  5046. }
  5047. void Client::ChangeTSLevel(int16 old_level, int16 new_level) {
  5048. if (new_level < 1) {
  5049. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  5050. return;
  5051. }
  5052. if ((player->GetTSLevel() >= 9 && player->GetTradeskillClass() == 1) || (player->GetTSLevel() >= 19 && (player->GetTradeskillClass() == 1 || player->GetTradeskillClass() == 2 || player->GetTradeskillClass() == 6 || player->GetTradeskillClass() == 10))) {
  5053. SimpleMessage(CHANNEL_COLOR_YELLOW, "You can not gain levels until you select your next class!");
  5054. return;
  5055. }
  5056. if (new_level > old_level)
  5057. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_TRADESKILL, new_level, player->GetTradeskillClass());
  5058. if (player->GetTSLevel() != new_level) {
  5059. player->SetTSLevel(new_level);
  5060. if (player->GetGroupMemberInfo()) {
  5061. player->UpdateGroupMemberInfo();
  5062. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  5063. }
  5064. }
  5065. // Only tradeskill skills should increace, and then only those related to your class
  5066. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  5067. if (level_update) {
  5068. level_update->setDataByName("old_level", old_level);
  5069. level_update->setDataByName("new_level", new_level);
  5070. level_update->setDataByName("type", 1);
  5071. QueuePacket(level_update->serialize());
  5072. safe_delete(level_update);
  5073. }
  5074. // provide new spells upon levelling
  5075. SendNewTradeskillSpells();
  5076. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  5077. if (command_packet) {
  5078. command_packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  5079. command_packet->setDataByName("anim_type", 1753);
  5080. QueuePacket(command_packet->serialize());
  5081. safe_delete(command_packet);
  5082. }
  5083. GetPlayer()->GetInfoStruct()->set_tradeskill_level(new_level);
  5084. GetPlayer()->SetTSLevel(new_level);
  5085. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  5086. GetPlayer()->SetCharSheetChanged(true);
  5087. Message(CHANNEL_NARRATIVE, "Your tradeskill level is now %i!", new_level);
  5088. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  5089. PlayerSkillList* player_skills = player->GetSkills();
  5090. int16 specialize_skill_cap = new_level * 5;
  5091. int16 artisan_skill_cap = std::max<int16>(specialize_skill_cap, 49);
  5092. int16 specialize_10_skill_cap = std::max<int16>(specialize_skill_cap, 99);
  5093. int8 ts_class = player->GetTradeskillClass();
  5094. int8 base_ts_class = classes.GetSecondaryTSBaseClass(ts_class);
  5095. int32 skill_id_1, skill_id_2, skill_id_3;
  5096. switch (base_ts_class) {
  5097. case ARTISAN:
  5098. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  5099. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  5100. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  5101. break;
  5102. case OUTFITTER:
  5103. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  5104. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  5105. skill_id_1 = SKILL_ID_TAILORING;
  5106. skill_id_2 = SKILL_ID_METALSHAPING;
  5107. skill_id_3 = SKILL_ID_METALWORKING;
  5108. if (ts_class == TAILOR) {
  5109. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  5110. skill_id_1 = 0;
  5111. }
  5112. else if (ts_class == ARMORER) {
  5113. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  5114. skill_id_2 = 0;
  5115. }
  5116. else if (ts_class == WEAPONSMITH) {
  5117. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  5118. skill_id_3 = 0;
  5119. }
  5120. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  5121. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  5122. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  5123. break;
  5124. case SCHOLAR:
  5125. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  5126. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  5127. skill_id_1 = SKILL_ID_SCRIBING;
  5128. skill_id_2 = SKILL_ID_CHEMISTRY;
  5129. skill_id_3 = SKILL_ID_ARTIFICING;
  5130. if (ts_class == SAGE) {
  5131. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  5132. skill_id_1 = 0;
  5133. }
  5134. else if (ts_class == ALCHEMIST) {
  5135. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  5136. skill_id_2 = 0;
  5137. }
  5138. else if (ts_class == JEWELER) {
  5139. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  5140. skill_id_3 = 0;
  5141. }
  5142. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  5143. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  5144. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  5145. break;
  5146. case CRAFTSMAN:
  5147. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  5148. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  5149. skill_id_1 = SKILL_ID_ARTISTRY;
  5150. skill_id_2 = SKILL_ID_FLETCHING;
  5151. skill_id_3 = SKILL_ID_SCULPTING;
  5152. if (ts_class == PROVISIONER) {
  5153. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  5154. skill_id_1 = 0;
  5155. }
  5156. else if (ts_class == WOODWORKER) {
  5157. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  5158. skill_id_2 = 0;
  5159. }
  5160. else if (ts_class == CARPENTER) {
  5161. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  5162. skill_id_3 = 0;
  5163. }
  5164. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  5165. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  5166. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  5167. break;
  5168. default:
  5169. break;
  5170. }
  5171. if (new_level > player->GetAdventureClass())
  5172. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, specialize_skill_cap);
  5173. Guild* guild = GetPlayer()->GetGuild();
  5174. if (guild) {
  5175. int8 event_type = 0;
  5176. if (new_level < 10)
  5177. event_type = GUILD_EVENT_GAINS_TS_LEVEL_1_10;
  5178. else if (new_level == 10)
  5179. event_type = GUILD_EVENT_GAINS_TS_LEVEL_10;
  5180. else if (new_level >= 11 && new_level < 20)
  5181. event_type = GUILD_EVENT_GAINS_TS_LEVEL_11_20;
  5182. else if (new_level == 20)
  5183. event_type = GUILD_EVENT_GAINS_TS_LEVEL_20;
  5184. else if (new_level >= 21 && new_level < 30)
  5185. event_type = GUILD_EVENT_GAINS_TS_LEVEL_21_30;
  5186. else if (new_level == 30)
  5187. event_type = GUILD_EVENT_GAINS_TS_LEVEL_30;
  5188. else if (new_level >= 31 && new_level < 40)
  5189. event_type = GUILD_EVENT_GAINS_TS_LEVEL_31_40;
  5190. else if (new_level == 40)
  5191. event_type = GUILD_EVENT_GAINS_TS_LEVEL_40;
  5192. else if (new_level >= 41 && new_level < 50)
  5193. event_type = GUILD_EVENT_GAINS_TS_LEVEL_41_50;
  5194. else if (new_level == 50)
  5195. event_type = GUILD_EVENT_GAINS_TS_LEVEL_50;
  5196. else if (new_level >= 51 && new_level < 60)
  5197. event_type = GUILD_EVENT_GAINS_TS_LEVEL_51_60;
  5198. else if (new_level == 60)
  5199. event_type = GUILD_EVENT_GAINS_TS_LEVEL_60;
  5200. else if (new_level >= 61 && new_level < 70)
  5201. event_type = GUILD_EVENT_GAINS_TS_LEVEL_61_70;
  5202. else if (new_level == 70)
  5203. event_type = GUILD_EVENT_GAINS_TS_LEVEL_70;
  5204. else if (new_level >= 71 && new_level < 80)
  5205. event_type = GUILD_EVENT_GAINS_TS_LEVEL_71_80;
  5206. else if (new_level == 80)
  5207. event_type = GUILD_EVENT_GAINS_TS_LEVEL_80;
  5208. 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());
  5209. 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());
  5210. guild->UpdateGuildMemberInfo(GetPlayer());
  5211. guild->SendGuildMember(GetPlayer());
  5212. guild->SendGuildMemberList();
  5213. }
  5214. // Need to send the trait list every time the players level changes
  5215. // Also need to force the char sheet update or else there can be a large delay from when you level
  5216. // to when you are actually able to select traits.
  5217. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  5218. QueuePacket(master_trait_list.GetTraitListPacket(this));
  5219. }
  5220. void Client::CloseLoot(int32 spawn_id) {
  5221. if (GetVersion() > 561) {
  5222. PacketStruct* packet = configReader.getStruct("WS_CloseWindow", GetVersion());
  5223. if (packet) {
  5224. packet->setDataByName("window_id", 4);
  5225. EQ2Packet* outapp = packet->serialize();
  5226. if (outapp) {
  5227. //DumpPacket(outapp);
  5228. QueuePacket(outapp);
  5229. }
  5230. safe_delete(packet);
  5231. }
  5232. }
  5233. if (spawn_id > 0) {
  5234. PacketStruct* packet = configReader.getStruct("WS_StoppedLooting", GetVersion());
  5235. if (packet) {
  5236. packet->setDataByName("spawn_id", spawn_id);
  5237. EQ2Packet* outapp = packet->serialize();
  5238. if (outapp)
  5239. QueuePacket(outapp);
  5240. safe_delete(packet);
  5241. }
  5242. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(spawn_id);
  5243. if (spawn) {
  5244. spawn->CloseLoot(GetPlayer());
  5245. }
  5246. }
  5247. }
  5248. string Client::GetCoinMessage(int32 total_coins) {
  5249. if (total_coins == 0) {
  5250. return " 0 Copper";
  5251. }
  5252. char tmp[64] = { 0 };
  5253. string message = "";
  5254. int32 val = 0;
  5255. if (total_coins >= 1000000) {
  5256. val = total_coins / 1000000;
  5257. total_coins -= 1000000 * val;
  5258. sprintf(tmp, " %u Platinum", val);
  5259. message.append(tmp);
  5260. memset(tmp, 0, 64);
  5261. }
  5262. if (total_coins >= 10000) {
  5263. val = total_coins / 10000;
  5264. total_coins -= 10000 * val;
  5265. sprintf(tmp, " %u Gold", val);
  5266. message.append(tmp);
  5267. memset(tmp, 0, 64);
  5268. }
  5269. if (total_coins >= 100) {
  5270. val = total_coins / 100;
  5271. total_coins -= 100 * val;
  5272. sprintf(tmp, " %u Silver", val);
  5273. message.append(tmp);
  5274. memset(tmp, 0, 64);
  5275. }
  5276. if (total_coins > 0) {
  5277. sprintf(tmp, " %u Copper", (int32)total_coins);
  5278. message.append(tmp);
  5279. }
  5280. return message;
  5281. }
  5282. void Client::SendLootResponsePacket(int32 total_coins, vector<Item*>* items, Spawn* entity, bool ignore_loot_tier) {
  5283. if (!entity) {
  5284. CloseLoot(0);
  5285. return;
  5286. }
  5287. if (total_coins > 0) {
  5288. player->AddCoins(total_coins);
  5289. //PlaySound("coin_cha_ching");
  5290. string message = "";
  5291. if (entity->GetHP() == 0) {
  5292. message = "You loot ";
  5293. entity->SetLootCoins(0, false);
  5294. }
  5295. else
  5296. message = "You receive ";
  5297. message.append(GetCoinMessage(total_coins));
  5298. if (entity->GetHP() == 0)
  5299. message.append(" from the corpse of ").append(entity->GetName());
  5300. int8 type = CHANNEL_LOOT;
  5301. SimpleMessage(type, message.c_str());
  5302. }
  5303. entity->StartLootTimer(GetPlayer());
  5304. PacketStruct* packet = configReader.getStruct("WS_UpdateLoot", GetVersion());
  5305. if (packet) {
  5306. entity->AddSpawnLootWindowCompleted(GetPlayer()->GetID(), false);
  5307. vector<Item*>::iterator itr;
  5308. int32 packet_size = 0;
  5309. EQ2Packet* outapp = 0;
  5310. uchar* data = 0;
  5311. vector<Item*> send_items;
  5312. if (items && items->size() > 0) {
  5313. for (int i = 0; i < items->size(); i++) {
  5314. Item* item = (*items)[i];
  5315. if (entity->GetLootMethod() > GroupLootMethod::METHOD_FFA && !ignore_loot_tier) {
  5316. bool skipItem = entity->IsItemInLootTier(item);
  5317. if (!skipItem) {
  5318. send_items.push_back(item);
  5319. }
  5320. }
  5321. else {
  5322. send_items.push_back(item);
  5323. }
  5324. }
  5325. }
  5326. if (GetVersion() >= 374) {
  5327. if (GetVersion() > 561) {
  5328. if (send_items.size() > 0) {
  5329. packet->setDataByName("loot_count", send_items.size());
  5330. packet->setDataByName("display", 1);
  5331. }
  5332. packet->setDataByName("loot_type", entity->GetLootMethod());
  5333. packet->setDataByName("lotto_timeout", entity->GetLootTimeRemaining() / 1000);
  5334. packet->setDataByName("loot_id", entity->GetID());
  5335. EQ2Packet* tmpPacket = packet->serialize();
  5336. packet_size += tmpPacket->size;
  5337. if (send_items.size() > 0) {
  5338. data = new uchar[send_items.size() * 1000 + packet_size];
  5339. memset(data, 0, send_items.size() * 1000 + packet_size);
  5340. }
  5341. else {
  5342. data = new uchar[packet_size];
  5343. memset(data, 0, packet_size);
  5344. }
  5345. uchar* ptr = data;
  5346. memcpy(ptr, tmpPacket->pBuffer, tmpPacket->size);
  5347. ptr += tmpPacket->size;
  5348. safe_delete(tmpPacket);
  5349. Item* item = 0;
  5350. if (send_items.size() > 0) {
  5351. for (itr = send_items.begin(); itr != send_items.end(); itr++) {
  5352. item = *itr;
  5353. memcpy(ptr, &item->details.item_id, sizeof(int32));
  5354. ptr += sizeof(int32);
  5355. packet_size += sizeof(int32);
  5356. tmpPacket = item->serialize(GetVersion(), true, GetPlayer(), false, 1, 0, false, true);
  5357. int8 offset = 0;
  5358. if (GetVersion() >= 1188) {
  5359. offset = 13;
  5360. }
  5361. else if (GetVersion() >= 860) {
  5362. offset = 11;
  5363. }
  5364. else if (GetVersion() <= 561) {
  5365. offset = 19;
  5366. }
  5367. else {
  5368. offset = 10;
  5369. }
  5370. memcpy(ptr, tmpPacket->pBuffer + offset, tmpPacket->size - offset);
  5371. ptr += tmpPacket->size - offset;
  5372. packet_size += tmpPacket->size - offset;
  5373. safe_delete(tmpPacket);
  5374. }
  5375. }
  5376. packet_size -= sizeof(int32);
  5377. memcpy(data, &packet_size, sizeof(int32));
  5378. packet_size += sizeof(int32);
  5379. outapp = new EQ2Packet(OP_ClientCmdMsg, data, packet_size);
  5380. }
  5381. else {
  5382. if (send_items.size() > 0) {
  5383. packet->setArrayLengthByName("loot_count", send_items.size());
  5384. Item* item = 0;
  5385. if (send_items.size() > 0) {
  5386. int i = 0;
  5387. for (itr = send_items.begin(); itr != send_items.end(); itr++) {
  5388. item = *itr;
  5389. packet->setArrayDataByName("loot_id", item->details.item_id, i);
  5390. packet->setItemArrayDataByName("item", item, GetPlayer(), i, 0, 2, true);
  5391. i++;
  5392. }
  5393. }
  5394. packet->setDataByName("display", 1);
  5395. }
  5396. packet->setDataByName("loot_type", entity->GetLootMethod()); // normal
  5397. packet->setDataByName("lotto_timeout", entity->GetLootTimeRemaining() / 1000); // 60 seconds
  5398. packet->setDataByName("spawn_id", entity->GetID());
  5399. outapp = packet->serialize();
  5400. }
  5401. }
  5402. else {
  5403. if (send_items.size() > 0) {
  5404. packet->setArrayLengthByName("loot_count", send_items.size());
  5405. for (int i = 0; i < send_items.size(); i++) {
  5406. Item* item = (send_items)[i];
  5407. packet->setArrayDataByName("name", item->name.c_str(), i);
  5408. packet->setArrayDataByName("item_id", item->details.item_id, i);
  5409. packet->setArrayDataByName("count", item->details.count, i);
  5410. packet->setArrayDataByName("icon", item->GetIcon(GetVersion()), i);
  5411. if (item->generic_info.skill_req1 > 0 && item->generic_info.skill_req1 < 0xFFFFFFFF)
  5412. packet->setArrayDataByName("ability_id", item->generic_info.skill_req1, i);
  5413. else if (item->generic_info.skill_req2 > 0 && item->generic_info.skill_req2 < 0xFFFFFFFF)
  5414. packet->setArrayDataByName("ability_id", item->generic_info.skill_req2, i);
  5415. else
  5416. packet->setArrayDataByName("ability_id", 0xFFFFFFFF, i);
  5417. }
  5418. }
  5419. packet->setDataByName("display", 1);
  5420. packet->setDataByName("loot_type", entity->GetLootMethod()); // normal
  5421. packet->setDataByName("lotto_timeout", entity->GetLootTimeRemaining() / 1000); // 60 seconds
  5422. packet->setDataByName("object_id", entity->GetID());
  5423. outapp = packet->serialize();
  5424. }
  5425. if (outapp) {
  5426. QueuePacket(outapp);
  5427. }
  5428. safe_delete_array(data);
  5429. safe_delete(packet);
  5430. if (!items || items->size() == 0)
  5431. CloseLoot(entity->GetID());
  5432. }
  5433. }
  5434. bool Client::LootSpawnByMethod(Spawn* entity) {
  5435. bool sentLoot = false;
  5436. bool startWithLooter = true;
  5437. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  5438. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  5439. if (gmi && gmi->group_id)
  5440. {
  5441. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  5442. if (group)
  5443. {
  5444. int8 auto_split_coin = group->GetGroupOptions()->auto_split;
  5445. bool isLeadGroup = group->IsInRaidGroup(group->GetID(), true);
  5446. bool isInRaid = group->IsInRaidGroup(group->GetID());
  5447. std::vector<int32> raidGroups;
  5448. group->GetRaidGroups(&raidGroups);
  5449. if (!isInRaid && raidGroups.size() < 1) {
  5450. raidGroups.push_back(group->GetID());
  5451. }
  5452. std::vector<int32>::iterator group_itr;
  5453. int32 split_coin_per_player = 0;
  5454. int32 coins_remain_after_split = entity->GetLootCoins();
  5455. int32 total_coins = entity->GetLootCoins();
  5456. bool foundLooterResetRaidRun = false;
  5457. int8 members_in_zone = 0;
  5458. for (group_itr = raidGroups.begin(); group_itr != raidGroups.end(); group_itr++) {
  5459. group = world.GetGroupManager()->GetGroup((*group_itr));
  5460. if (!group)
  5461. continue;
  5462. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  5463. deque<GroupMemberInfo*>* members = group->GetMembers();
  5464. for (int8 i = 0; i < members->size(); i++) {
  5465. Entity* member = members->at(i)->member;
  5466. if (!member || !member->IsPlayer())
  5467. continue;
  5468. if (member->GetZone() != GetPlayer()->GetZone())
  5469. continue;
  5470. members_in_zone++;
  5471. }
  5472. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  5473. }
  5474. if (auto_split_coin) {
  5475. if (members_in_zone < 1) // this should not happen, but divide by zero checked
  5476. members_in_zone = 1;
  5477. split_coin_per_player = entity->GetLootCoins() / members_in_zone;
  5478. coins_remain_after_split = entity->GetLootCoins() - (split_coin_per_player * members_in_zone);
  5479. entity->SetLootCoins(0, false);
  5480. }
  5481. int32 lootGroup = 0;
  5482. for (group_itr = raidGroups.begin(); group_itr != raidGroups.end();) {
  5483. group = world.GetGroupManager()->GetGroup((*group_itr));
  5484. if (!group)
  5485. continue;
  5486. isLeadGroup = group->IsInRaidGroup((*group_itr), true);
  5487. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  5488. deque<GroupMemberInfo*>* members = group->GetMembers();
  5489. 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);
  5490. for (int8 i = 0; i < members->size(); i++) {
  5491. Entity* member = members->at(i)->member;
  5492. if (!member || !member->IsPlayer())
  5493. continue;
  5494. if (member->GetZone() != GetPlayer()->GetZone())
  5495. continue;
  5496. // this will make sure we properly send the loot window to the initial requester if there is no item rarity matches
  5497. if (startWithLooter && member != GetPlayer())
  5498. continue;
  5499. else if (!startWithLooter && member == GetPlayer())
  5500. continue;
  5501. if (auto_split_coin) {
  5502. int32 coin_recv = 0;
  5503. if (member == GetPlayer() && auto_split_coin && (split_coin_per_player + coins_remain_after_split) > 0) {
  5504. coin_recv = split_coin_per_player + coins_remain_after_split;
  5505. player->AddCoins(split_coin_per_player + coins_remain_after_split);
  5506. if (coins_remain_after_split > 0) // overflow of coin division went to the first player
  5507. coins_remain_after_split = 0;
  5508. }
  5509. else if (split_coin_per_player > 0) {
  5510. coin_recv = split_coin_per_player;
  5511. player->AddCoins(split_coin_per_player);
  5512. }
  5513. if (coin_recv && ((Player*)member)->GetClient()) {
  5514. ((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(coin_recv).c_str());
  5515. }
  5516. }
  5517. switch (entity->GetLootMethod()) {
  5518. case GroupLootMethod::METHOD_LOTTO:
  5519. case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
  5520. if (((Player*)member)->GetClient()) {
  5521. switch (member->GetInfoStruct()->get_group_auto_loot_method()) {
  5522. case 1: { // lotto, need
  5523. if (entity->GetLootMethod() == GroupLootMethod::METHOD_LOTTO) {
  5524. entity->AddLottoItemRequest(0xFFFFFFFF, GetPlayer()->GetID());
  5525. }
  5526. else { // *need* before greed
  5527. entity->AddNeedGreedItemRequest(0xFFFFFFFF, GetPlayer()->GetID(), true);
  5528. }
  5529. entity->AddSpawnLootWindowCompleted(member->GetID(), true);
  5530. // if it already exists we have to override the setting
  5531. entity->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
  5532. break;
  5533. }
  5534. case 2: { // decline
  5535. entity->AddSpawnLootWindowCompleted(member->GetID(), true);
  5536. // if it already exists we have to override the setting
  5537. entity->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
  5538. break;
  5539. }
  5540. default: { // presume 0 or higher than 2
  5541. ((Player*)member)->GetClient()->SendLootResponsePacket((!auto_split_coin && member == GetPlayer()) ? entity->GetLootCoins() : 0, entity->GetLootItems(), entity, true);
  5542. break;
  5543. }
  5544. }
  5545. sentLoot = true;
  5546. }
  5547. break;
  5548. }
  5549. case GroupLootMethod::METHOD_ROUND_ROBIN: {
  5550. entity->AddSpawnLootWindowCompleted(member->GetID(), true);
  5551. sentLoot = true;
  5552. break;
  5553. }
  5554. case GroupLootMethod::METHOD_LEADER: {
  5555. if ((!isInRaid || (isInRaid && isLeadGroup)) && member->GetGroupMemberInfo()->leader)
  5556. ((Player*)member)->GetClient()->SendLootResponsePacket((!auto_split_coin && member == GetPlayer()) ? entity->GetLootCoins() : 0, entity->GetLootItems(), entity);
  5557. break;
  5558. }
  5559. case GroupLootMethod::METHOD_FFA: {
  5560. if (member == GetPlayer()) {
  5561. ((Player*)member)->GetClient()->SendLootResponsePacket((!auto_split_coin && member == GetPlayer()) ? entity->GetLootCoins() : 0, entity->GetLootItems(), entity);
  5562. }
  5563. break;
  5564. }
  5565. }
  5566. if (startWithLooter) {
  5567. startWithLooter = false;
  5568. foundLooterResetRaidRun = true; // we got it, shouldn't hit this again
  5569. break;
  5570. }
  5571. }
  5572. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  5573. if (foundLooterResetRaidRun) {
  5574. group_itr = raidGroups.begin();
  5575. foundLooterResetRaidRun = false; // disable running it again
  5576. if (entity->GetLootMethod() == GroupLootMethod::METHOD_LEADER)
  5577. break;
  5578. }
  5579. else
  5580. group_itr++;
  5581. }
  5582. }
  5583. }
  5584. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  5585. return sentLoot;
  5586. }
  5587. void Client::LootSpawnRequest(Spawn* entity, bool attemptDisarm) {
  5588. bool lootAllowed = false;
  5589. bool sentLoot = false;
  5590. std::vector<int32> item_list;
  5591. if (entity->IsNPC()) {
  5592. entity->LockLoot();
  5593. lootAllowed = ((NPC*)entity)->Brain()->CheckLootAllowed(GetPlayer());
  5594. entity->UnlockLoot();
  5595. if (lootAllowed) {
  5596. OpenChest(entity, attemptDisarm);
  5597. }
  5598. else {
  5599. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not allowed to loot at this time.");
  5600. return;
  5601. }
  5602. entity->LockLoot();
  5603. if (((NPC*)entity)->Brain()->CheckLootAllowed(GetPlayer())) {
  5604. lootAllowed = true;
  5605. if ((sentLoot = LootSpawnByMethod(entity))) {
  5606. entity->GetLootItemsList(&item_list);
  5607. }
  5608. else {
  5609. SendLootResponsePacket(entity->GetLootCoins(), entity->GetLootItems(), entity);
  5610. }
  5611. }
  5612. entity->UnlockLoot();
  5613. if (lootAllowed) {
  5614. entity->DistributeGroupLoot_RoundRobin(&item_list, true);
  5615. }
  5616. }
  5617. }
  5618. void Client::OpenChest(Spawn* entity, bool attemptDisarm)
  5619. {
  5620. if (!entity)
  5621. return;
  5622. int8 chest_difficulty = 0;
  5623. int32 state = 0;
  5624. // Check for the chest and set the action state
  5625. /*4034 = small chest | 5864 = treasure chest | 5865 = ornate treasure chest | 4015 = exquisite chest*/
  5626. string modelName;
  5627. if (entity->GetModelType() == 4034) {
  5628. // small chest, open with copper coins
  5629. // does not include traps, however can be disarmed
  5630. chest_difficulty = 1;
  5631. state = 11899;
  5632. modelName.append("Small Chest");
  5633. }
  5634. else if (entity->GetModelType() == 5864) {
  5635. // treasure chest, open with silver coins
  5636. chest_difficulty = 2;
  5637. state = 11901;
  5638. modelName.append("Treasure Chest");
  5639. }
  5640. else if (entity->GetModelType() == 5865) {
  5641. // ornate chest, open with gold coins
  5642. chest_difficulty = 3;
  5643. state = 11900;
  5644. modelName.append("Ornate Chest");
  5645. }
  5646. else if (entity->GetModelType() == 4015) {
  5647. // exquisite chest, open with gold coins and jewels as well as a glow effect
  5648. chest_difficulty = 5;
  5649. state = 11898;
  5650. modelName.append("Exquisite Chest");
  5651. }
  5652. bool firstChestOpen = false;
  5653. if (chest_difficulty > 0 && !entity->HasTrapTriggered())
  5654. {
  5655. ChestTrap::ChestTrapInfo nextTrap;
  5656. bool ret = chest_trap_list.GetNextTrap(GetCurrentZone()->GetZoneID(), chest_difficulty, &nextTrap);
  5657. Skill* disarmSkill = GetPlayer()->GetSkillByName("Disarm Trap", false);
  5658. firstChestOpen = true;
  5659. entity->SetTrapTriggered(true, state);
  5660. if (ret)
  5661. {
  5662. if (disarmSkill && attemptDisarm)
  5663. {
  5664. if (disarmSkill->CheckDisarmSkill(entity->GetLevel(), chest_difficulty) < 1)
  5665. {
  5666. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  5667. rule_manager.GetZoneRule(GetCurrentZoneID(), R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  5668. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  5669. }
  5670. else
  5671. {
  5672. Message(CHANNEL_NARRATIVE, "You disarm the trap on %s", modelName.c_str());
  5673. }
  5674. // despite fail/succeed we should always try to increase skill if disarm is available
  5675. GetPlayer()->GetSkillByName("Disarm Trap", true);
  5676. }
  5677. else // no disarm skill, always fail
  5678. {
  5679. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  5680. rule_manager.GetZoneRule(GetCurrentZoneID(), R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  5681. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  5682. }
  5683. }
  5684. }
  5685. else if (!entity->HasTrapTriggered())
  5686. {
  5687. firstChestOpen = true;
  5688. entity->SetTrapTriggered(true, state);
  5689. }
  5690. // We set the visual state with out updating so those not in range will see it opened when it is finally sent to them,
  5691. // for those in range the SendStateCommand will cause it to animate open.
  5692. // players not currently in radius will have it queued with client->QueueStateCommand when SendSpawn takes place
  5693. if (firstChestOpen)
  5694. GetCurrentZone()->SendStateCommand(entity, state);
  5695. }
  5696. void Client::CastGroupOrSelf(Entity* source, uint32 spellID, uint32 spellTier, float restrictiveRadius)
  5697. {
  5698. Spell* spell = master_spell_list.GetSpell(spellID, spellTier);
  5699. SpellProcess* spellProcess = GetCurrentZone()->GetSpellProcess();
  5700. if (source == NULL)
  5701. source = (Entity*)GetPlayer();
  5702. if (spell)
  5703. {
  5704. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  5705. if (gmi && gmi->group_id)
  5706. {
  5707. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  5708. if (group)
  5709. {
  5710. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  5711. deque<GroupMemberInfo*>* members = group->GetMembers();
  5712. for (int8 i = 0; i < members->size(); i++) {
  5713. Entity* member = members->at(i)->member;
  5714. if (!member)
  5715. continue;
  5716. if (!member->Alive() || (member->GetZone() != source->GetZone()))
  5717. continue;
  5718. // if we have a radius provided then check if the group member is outside the radius or not
  5719. if (restrictiveRadius > 0.0f && member->GetDistance(source) > restrictiveRadius)
  5720. continue;
  5721. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  5722. }
  5723. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  5724. }
  5725. }
  5726. else
  5727. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  5728. }
  5729. }
  5730. Spawn* Client::GetBanker() {
  5731. return banker;
  5732. }
  5733. void Client::SetBanker(Spawn* in_banker) {
  5734. banker = in_banker;
  5735. }
  5736. void Client::Bank(Spawn* banker, bool cancel) {
  5737. if (banker && banker->primary_command_list.size() > 0 && banker->primary_command_list[0]->command == "bank") {
  5738. if (!cancel)
  5739. SetBanker(banker);
  5740. else
  5741. SetBanker(0);
  5742. PacketStruct* packet = configReader.getStruct("WS_UpdateBank", GetVersion());
  5743. if (packet) {
  5744. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(banker));
  5745. int64 coins = GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + GetPlayer()->GetInfoStruct()->get_bank_coin_silver() * 100 +
  5746. GetPlayer()->GetInfoStruct()->get_bank_coin_gold() * 10000 + (int64)GetPlayer()->GetInfoStruct()->get_bank_coin_plat() * 1000000;
  5747. int32 coins1, coins2;
  5748. coins1 = ((int32*)&coins)[0];
  5749. coins2 = ((int32*)&coins)[1];
  5750. packet->setDataByName("bank_coins", coins1);
  5751. packet->setDataByName("bank_coins2", coins2);
  5752. packet->setDataByName("copper", GetPlayer()->GetInfoStruct()->get_coin_copper());
  5753. packet->setDataByName("silver", GetPlayer()->GetInfoStruct()->get_coin_silver());
  5754. packet->setDataByName("gold", GetPlayer()->GetInfoStruct()->get_coin_gold());
  5755. packet->setDataByName("plat", GetPlayer()->GetInfoStruct()->get_coin_plat());
  5756. if (!cancel)
  5757. packet->setDataByName("display", 1);
  5758. QueuePacket(packet->serialize());
  5759. safe_delete(packet);
  5760. }
  5761. }
  5762. }
  5763. bool Client::BankHasCoin(int64 amount) {
  5764. int32 tmp = 0;
  5765. if (amount <= 0)
  5766. return 0;
  5767. //plat
  5768. if (amount >= 1000000) {
  5769. tmp = amount / 1000000;
  5770. int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
  5771. if (bank_coins_plat >= tmp)
  5772. return 1;
  5773. }
  5774. //gold
  5775. if (amount >= 10000) {
  5776. tmp = amount / 10000;
  5777. int32 bank_coins_gold = GetPlayer()->GetBankCoinsGold();
  5778. if (bank_coins_gold >= tmp)
  5779. return 1;
  5780. }
  5781. //silver
  5782. if (amount >= 100) {
  5783. tmp = amount / 100;
  5784. int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
  5785. if (bank_coins_silver >= tmp)
  5786. return 1;
  5787. }
  5788. //copper
  5789. if (amount > 0) {
  5790. int32 bank_coins_copper = GetPlayer()->GetBankCoinsCopper();
  5791. if (bank_coins_copper >= amount)
  5792. return 1;
  5793. }
  5794. return 0;
  5795. }
  5796. bool Client::BankWithdrawalNoBanker(int64 amount) {
  5797. bool cheater = false;
  5798. if (amount > 0) {
  5799. string withdrawal = "";
  5800. char withdrawal_data[512] = { 0 };
  5801. int32 tmp = 0;
  5802. if (amount >= 1000000) {
  5803. tmp = amount / 1000000;
  5804. int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
  5805. if (tmp > bank_coins_plat)
  5806. cheater = true;
  5807. else {
  5808. GetPlayer()->GetInfoStruct()->set_bank_coin_plat(bank_coins_plat - tmp);
  5809. GetPlayer()->GetInfoStruct()->add_coin_plat(tmp);
  5810. amount -= (int64)tmp * 1000000;
  5811. sprintf(withdrawal_data, "%u Platinum ", tmp);
  5812. withdrawal.append(withdrawal_data);
  5813. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5814. }
  5815. }
  5816. if (!cheater && amount >= 10000) {
  5817. tmp = amount / 10000;
  5818. if (tmp > GetPlayer()->GetBankCoinsGold())
  5819. cheater = true;
  5820. else {
  5821. int32 bank_coins_gold = GetPlayer()->GetInfoStruct()->get_bank_coin_gold();
  5822. bank_coins_gold -= tmp;
  5823. if ((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) > 100) {
  5824. GetPlayer()->GetInfoStruct()->set_coin_gold((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) - 100);
  5825. GetPlayer()->GetInfoStruct()->add_coin_plat(1);
  5826. }
  5827. else
  5828. GetPlayer()->GetInfoStruct()->add_coin_gold(tmp);
  5829. amount -= tmp * 10000;
  5830. sprintf(withdrawal_data, "%u Gold ", tmp);
  5831. withdrawal.append(withdrawal_data);
  5832. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5833. }
  5834. }
  5835. if (!cheater && amount >= 100) {
  5836. tmp = amount / 100;
  5837. int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
  5838. if (tmp > bank_coins_silver)
  5839. cheater = true;
  5840. else {
  5841. GetPlayer()->GetInfoStruct()->set_bank_coin_silver(bank_coins_silver - tmp);
  5842. if ((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) > 100) {
  5843. GetPlayer()->GetInfoStruct()->set_coin_silver((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) - 100);
  5844. GetPlayer()->GetInfoStruct()->add_coin_gold(1);
  5845. }
  5846. else
  5847. GetPlayer()->GetInfoStruct()->add_coin_silver(tmp);
  5848. amount -= tmp * 100;
  5849. sprintf(withdrawal_data, "%u Silver ", tmp);
  5850. withdrawal.append(withdrawal_data);
  5851. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5852. }
  5853. }
  5854. if (!cheater) {
  5855. if (amount > 0) {
  5856. sprintf(withdrawal_data, "%u Copper ", (int32)amount);
  5857. withdrawal.append(withdrawal_data);
  5858. int32 bank_coin_copper = GetPlayer()->GetInfoStruct()->get_bank_coin_copper();
  5859. GetPlayer()->GetInfoStruct()->set_bank_coin_copper(bank_coin_copper - amount);
  5860. if ((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) > 100) {
  5861. GetPlayer()->GetInfoStruct()->set_coin_copper((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) - 100);
  5862. GetPlayer()->GetInfoStruct()->add_coin_silver(1);
  5863. }
  5864. else
  5865. GetPlayer()->GetInfoStruct()->add_coin_copper(amount);
  5866. }
  5867. if (withdrawal.length() > 0) {
  5868. withdrawal.append("withdrawn ");
  5869. sprintf(withdrawal_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  5870. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  5871. withdrawal.append(withdrawal_data);
  5872. SimpleMessage(CHANNEL_NARRATIVE, withdrawal.c_str());
  5873. return 1;
  5874. }
  5875. }
  5876. else
  5877. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  5878. return 0;
  5879. }
  5880. return 0;
  5881. }
  5882. void Client::BankWithdrawal(int64 amount) {
  5883. bool cheater = false;
  5884. if (GetBanker() && amount > 0) {
  5885. string withdrawal = "";
  5886. char withdrawal_data[512] = { 0 };
  5887. int32 tmp = 0;
  5888. if (amount >= 1000000) {
  5889. tmp = amount / 1000000;
  5890. int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
  5891. if (tmp > bank_coins_plat)
  5892. cheater = true;
  5893. else {
  5894. GetPlayer()->GetInfoStruct()->set_bank_coin_plat(bank_coins_plat - tmp);
  5895. GetPlayer()->GetInfoStruct()->add_coin_plat(tmp);
  5896. amount -= (int64)tmp * 1000000;
  5897. sprintf(withdrawal_data, "%u Platinum ", tmp);
  5898. withdrawal.append(withdrawal_data);
  5899. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5900. }
  5901. }
  5902. if (!cheater && amount >= 10000) {
  5903. tmp = amount / 10000;
  5904. if (tmp > GetPlayer()->GetBankCoinsGold())
  5905. cheater = true;
  5906. else {
  5907. int32 bank_coins_gold = GetPlayer()->GetInfoStruct()->get_bank_coin_gold();
  5908. bank_coins_gold -= tmp;
  5909. if ((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) > 100) {
  5910. GetPlayer()->GetInfoStruct()->set_coin_gold((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) - 100);
  5911. GetPlayer()->GetInfoStruct()->add_coin_plat(1);
  5912. }
  5913. else
  5914. GetPlayer()->GetInfoStruct()->add_coin_gold(tmp);
  5915. amount -= tmp * 10000;
  5916. sprintf(withdrawal_data, "%u Gold ", tmp);
  5917. withdrawal.append(withdrawal_data);
  5918. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5919. }
  5920. }
  5921. if (!cheater && amount >= 100) {
  5922. tmp = amount / 100;
  5923. int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
  5924. if (tmp > bank_coins_silver)
  5925. cheater = true;
  5926. else {
  5927. GetPlayer()->GetInfoStruct()->set_bank_coin_silver(bank_coins_silver - tmp);
  5928. if ((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) > 100) {
  5929. GetPlayer()->GetInfoStruct()->set_coin_silver((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) - 100);
  5930. GetPlayer()->GetInfoStruct()->add_coin_gold(1);
  5931. }
  5932. else
  5933. GetPlayer()->GetInfoStruct()->add_coin_silver(tmp);
  5934. amount -= tmp * 100;
  5935. sprintf(withdrawal_data, "%u Silver ", tmp);
  5936. withdrawal.append(withdrawal_data);
  5937. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5938. }
  5939. }
  5940. if (!cheater) {
  5941. if (amount > 0) {
  5942. sprintf(withdrawal_data, "%u Copper ", (int32)amount);
  5943. withdrawal.append(withdrawal_data);
  5944. int32 bank_coin_copper = GetPlayer()->GetInfoStruct()->get_bank_coin_copper();
  5945. GetPlayer()->GetInfoStruct()->set_bank_coin_copper(bank_coin_copper - amount);
  5946. if ((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) > 100) {
  5947. GetPlayer()->GetInfoStruct()->set_coin_copper((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) - 100);
  5948. GetPlayer()->GetInfoStruct()->add_coin_silver(1);
  5949. }
  5950. else
  5951. GetPlayer()->GetInfoStruct()->add_coin_copper(amount);
  5952. }
  5953. if (withdrawal.length() > 0) {
  5954. withdrawal.append("withdrawn ");
  5955. sprintf(withdrawal_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  5956. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  5957. withdrawal.append(withdrawal_data);
  5958. SimpleMessage(CHANNEL_NARRATIVE, withdrawal.c_str());
  5959. }
  5960. }
  5961. else
  5962. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  5963. player->SetCharSheetChanged(true);
  5964. Bank(banker);
  5965. }
  5966. }
  5967. void Client::BankDeposit(int64 amount) {
  5968. bool cheater = false;
  5969. if (GetBanker() && amount > 0) {
  5970. int32 tmp = 0;
  5971. char deposit_data[512] = { 0 };
  5972. string deposit = "";
  5973. if (amount >= 1000000) {
  5974. tmp = amount / 1000000;
  5975. if (tmp > GetPlayer()->GetCoinsPlat())
  5976. cheater = true;
  5977. else {
  5978. GetPlayer()->GetInfoStruct()->add_bank_coin_plat(tmp);
  5979. GetPlayer()->GetInfoStruct()->set_coin_plat(GetPlayer()->GetInfoStruct()->get_coin_plat() - tmp);
  5980. amount -= (int64)tmp * 1000000;
  5981. sprintf(deposit_data, "%u Platinum ", tmp);
  5982. deposit.append(deposit_data);
  5983. memset(deposit_data, 0, sizeof(deposit_data));
  5984. }
  5985. }
  5986. if (!cheater && amount >= 10000) {
  5987. tmp = amount / 10000;
  5988. if (tmp > GetPlayer()->GetCoinsGold())
  5989. cheater = true;
  5990. else {
  5991. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_gold() + tmp) > 100) {
  5992. GetPlayer()->GetInfoStruct()->set_bank_coin_gold((GetPlayer()->GetInfoStruct()->get_bank_coin_gold() + tmp) - 100);
  5993. GetPlayer()->GetInfoStruct()->add_bank_coin_plat(1);
  5994. }
  5995. else
  5996. GetPlayer()->GetInfoStruct()->add_bank_coin_gold(tmp);
  5997. GetPlayer()->GetInfoStruct()->set_coin_gold(GetPlayer()->GetInfoStruct()->get_coin_gold() - tmp);
  5998. amount -= tmp * 10000;
  5999. sprintf(deposit_data, "%u Gold ", tmp);
  6000. deposit.append(deposit_data);
  6001. memset(deposit_data, 0, sizeof(deposit_data));
  6002. }
  6003. }
  6004. if (!cheater && amount >= 100) {
  6005. tmp = amount / 100;
  6006. if (tmp > GetPlayer()->GetCoinsSilver())
  6007. cheater = true;
  6008. else {
  6009. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_silver() + tmp) > 100) {
  6010. GetPlayer()->GetInfoStruct()->set_bank_coin_silver((GetPlayer()->GetInfoStruct()->get_bank_coin_silver() + tmp) - 100);
  6011. GetPlayer()->GetInfoStruct()->add_bank_coin_gold(1);
  6012. }
  6013. else
  6014. GetPlayer()->GetInfoStruct()->add_bank_coin_silver(tmp);
  6015. GetPlayer()->GetInfoStruct()->set_coin_silver(GetPlayer()->GetInfoStruct()->get_coin_silver() - tmp);
  6016. amount -= tmp * 100;
  6017. sprintf(deposit_data, "%u Silver ", tmp);
  6018. deposit.append(deposit_data);
  6019. memset(deposit_data, 0, sizeof(deposit_data));
  6020. }
  6021. }
  6022. if (!cheater) {
  6023. if (amount > 0) {
  6024. sprintf(deposit_data, "%u Copper ", (int32)amount);
  6025. deposit.append(deposit_data);
  6026. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + amount) > 100) {
  6027. GetPlayer()->GetInfoStruct()->set_bank_coin_copper((GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + amount) - 100);
  6028. GetPlayer()->GetInfoStruct()->add_bank_coin_silver(1);
  6029. }
  6030. else
  6031. GetPlayer()->GetInfoStruct()->add_bank_coin_copper(amount);
  6032. GetPlayer()->GetInfoStruct()->set_coin_copper(GetPlayer()->GetInfoStruct()->get_coin_copper() - amount);
  6033. }
  6034. if (deposit.length() > 0) {
  6035. deposit.append("deposited ");
  6036. sprintf(deposit_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  6037. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  6038. deposit.append(deposit_data);
  6039. SimpleMessage(CHANNEL_NARRATIVE, deposit.c_str());
  6040. }
  6041. }
  6042. else
  6043. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  6044. player->SetCharSheetChanged(true);
  6045. Bank(banker);
  6046. }
  6047. }
  6048. void Client::AddPendingQuestAcceptReward(Quest* quest)
  6049. {
  6050. std::unique_lock lock(MPendingQuestAccept);
  6051. pending_quest_accept.push_back(quest->GetQuestID());
  6052. }
  6053. void Client::AddPendingQuestReward(Quest* quest, bool update, bool is_temporary, std::string description) {
  6054. QueueQuestReward(quest->GetQuestID(), is_temporary, false, false, (is_temporary ? quest->GetCoinTmpReward() : 0),
  6055. (is_temporary ? quest->GetStatusTmpReward() : 0), description, false, 0);
  6056. quest_updates = update;
  6057. if (quest_updates) {
  6058. SaveQuestRewardData(true);
  6059. }
  6060. }
  6061. 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) {
  6062. if (HasQuestRewardQueued(quest_id, is_temporary, is_collection))
  6063. return;
  6064. QuestRewardData* data = new QuestRewardData;
  6065. data->quest_id = quest_id;
  6066. data->is_temporary = is_temporary;
  6067. data->is_collection = is_collection;
  6068. data->has_displayed = has_displayed;
  6069. data->tmp_coin = tmp_coin;
  6070. data->tmp_status = tmp_status;
  6071. data->description = std::string(description);
  6072. data->db_saved = db_saved;
  6073. data->db_index = index;
  6074. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  6075. quest_pending_reward.push_back(data);
  6076. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  6077. }
  6078. bool Client::HasQuestRewardQueued(int32 quest_id, bool is_temporary, bool is_collection) {
  6079. bool success = false;
  6080. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  6081. if (quest_pending_reward.size() > 0) {
  6082. vector<QuestRewardData*>::iterator itr;
  6083. for (itr = quest_pending_reward.begin(); itr != quest_pending_reward.end(); itr++) {
  6084. int32 questID = (*itr)->quest_id;
  6085. bool temporary = (*itr)->is_temporary;
  6086. bool collection = (*itr)->is_collection;
  6087. if (questID == quest_id && is_temporary == temporary && is_collection == collection) {
  6088. success = true;
  6089. break;
  6090. }
  6091. }
  6092. }
  6093. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  6094. return success;
  6095. }
  6096. void Client::RemoveQueuedQuestReward() {
  6097. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  6098. if (quest_pending_reward.size() > 0) {
  6099. QuestRewardData* data = quest_pending_reward.at(0);
  6100. if (data->db_saved) {
  6101. Query query;
  6102. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete FROM character_quest_rewards where char_id = %u and indexed = %u", GetCharacterID(), data->db_index);
  6103. if (data->is_temporary && data->quest_id) {
  6104. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete FROM character_quest_temporary_rewards where char_id = %u and quest_id = %u", GetCharacterID(), data->quest_id);
  6105. }
  6106. }
  6107. quest_pending_reward.erase(quest_pending_reward.begin());
  6108. }
  6109. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  6110. SaveQuestRewardData(true);
  6111. }
  6112. void Client::AddPendingQuestUpdate(int32 quest_id, int32 step_id, int32 progress) {
  6113. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  6114. quest_pending_updates[quest_id][step_id] = progress;
  6115. quest_updates = true;
  6116. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  6117. }
  6118. void Client::ProcessQuestUpdates() {
  6119. if (!IsReadyForUpdates())
  6120. return;
  6121. if (quest_pending_updates.size() > 0) {
  6122. map<int32, map<int32, int32> > tmp_quest_updates;
  6123. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  6124. tmp_quest_updates.insert(quest_pending_updates.begin(), quest_pending_updates.end());
  6125. quest_pending_updates.clear();
  6126. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  6127. map<int32, map<int32, int32> >::iterator quest_itr;
  6128. map<int32, int32>::iterator step_itr;
  6129. for (quest_itr = tmp_quest_updates.begin(); quest_itr != tmp_quest_updates.end(); quest_itr++) {
  6130. for (step_itr = quest_itr->second.begin(); step_itr != quest_itr->second.end(); step_itr++) {
  6131. if (step_itr->second == 0xFFFFFFFF) {
  6132. SetStepComplete(quest_itr->first, step_itr->first);
  6133. player->SendQuestRequiredSpawns(quest_itr->first);
  6134. }
  6135. else
  6136. AddStepProgress(quest_itr->first, step_itr->first, step_itr->second);
  6137. }
  6138. }
  6139. }
  6140. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  6141. if (quest_pending_reward.size() > 0) {
  6142. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  6143. // only able to display one reward at a time
  6144. if (GetPlayer()->IsActiveReward())
  6145. return;
  6146. Query query;
  6147. vector<QuestRewardData*>::iterator itr;
  6148. vector<QuestRewardData*> tmp_quest_rewards;
  6149. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  6150. tmp_quest_rewards.insert(tmp_quest_rewards.begin(), quest_pending_reward.begin(), quest_pending_reward.begin() + 1);
  6151. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  6152. bool delete_first = false;
  6153. for (itr = tmp_quest_rewards.begin(); itr != tmp_quest_rewards.end();) {
  6154. int32 questID = (*itr)->quest_id;
  6155. if ((*itr)->is_collection && GetPlayer()->GetPendingCollectionReward()) {
  6156. DisplayCollectionComplete(GetPlayer()->GetPendingCollectionReward());
  6157. GetPlayer()->SetActiveReward(true);
  6158. (*itr)->has_displayed = true;
  6159. UpdateCharacterRewardData((*itr));
  6160. break;
  6161. }
  6162. else if (questID > 0 && GetPlayer()->UpdateQuestReward(questID, (*itr))) {
  6163. (*itr)->has_displayed = true;
  6164. UpdateCharacterRewardData((*itr));
  6165. // only able to display one reward at a time
  6166. break;
  6167. }
  6168. else {
  6169. delete_first = true;
  6170. LogWrite(CCLIENT__ERROR, 0, "Client", "Quest ID %u missing for Player %s, deleting quest id from tmp_quest_rewards.", questID, GetPlayer()->GetName());
  6171. break;
  6172. }
  6173. }
  6174. if (delete_first) {
  6175. RemoveQueuedQuestReward();
  6176. }
  6177. }
  6178. else {
  6179. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  6180. }
  6181. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  6182. if (quest_pending_reward.size() > 0) {
  6183. quest_updates = true;
  6184. }
  6185. else {
  6186. quest_updates = false;
  6187. }
  6188. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  6189. }
  6190. void Client::CheckQuestQueue() {
  6191. MQuestQueue.writelock();
  6192. last_update_time = 0;
  6193. vector<QueuedQuest*>::iterator itr;
  6194. for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
  6195. if (!GetPlayer()->SendQuestStepUpdate((*itr)->quest_id, (*itr)->step, (*itr)->display_quest_helper)) {
  6196. LogWrite(CCLIENT__ERROR, 0, "Client", "Queued Quest ID %u missing for Player %s, cannot send quest step update.", (*itr)->quest_id, GetPlayer()->GetName());
  6197. }
  6198. safe_delete((*itr));
  6199. }
  6200. quest_queue.clear();
  6201. MQuestQueue.releasewritelock();
  6202. }
  6203. void Client::SetStepComplete(int32 quest_id, int32 step) {
  6204. Quest* quest = player->SetStepComplete(quest_id, step);
  6205. if (quest) {
  6206. SendQuestUpdate(quest);
  6207. GetCurrentZone()->SendQuestUpdates(this);
  6208. }
  6209. }
  6210. void Client::AddStepProgress(int32 quest_id, int32 step, int32 progress) {
  6211. Quest* quest = player->AddStepProgress(quest_id, step, progress);
  6212. if (quest) {
  6213. SendQuestUpdate(quest);
  6214. GetCurrentZone()->SendQuestUpdates(this);
  6215. }
  6216. }
  6217. void Client::CheckPlayerQuestsKillUpdate(Spawn* spawn) {
  6218. bool hadUpdates = false;
  6219. vector<Quest*>* quest_updates = player->CheckQuestsKillUpdate(spawn);
  6220. if (quest_updates) {
  6221. for (int32 i = 0; i < quest_updates->size(); i++)
  6222. {
  6223. SendQuestUpdate(quest_updates->at(i));
  6224. hadUpdates = true;
  6225. }
  6226. }
  6227. safe_delete(quest_updates);
  6228. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  6229. if (quest_failures) {
  6230. for (int32 i = 0; i < quest_failures->size(); i++)
  6231. {
  6232. SendQuestFailure(quest_failures->at(i));
  6233. hadUpdates = true;
  6234. }
  6235. }
  6236. safe_delete(quest_failures);
  6237. if (hadUpdates)
  6238. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  6239. }
  6240. void Client::CheckPlayerQuestsChatUpdate(Spawn* spawn) {
  6241. vector<Quest*>* quest_updates = player->CheckQuestsChatUpdate(spawn);
  6242. if (quest_updates) {
  6243. for (int32 i = 0; i < quest_updates->size(); i++)
  6244. SendQuestUpdate(quest_updates->at(i));
  6245. GetCurrentZone()->SendQuestUpdates(this);
  6246. }
  6247. safe_delete(quest_updates);
  6248. }
  6249. void Client::CheckPlayerQuestsItemUpdate(Item* item) {
  6250. vector<Quest*>* quest_updates = player->CheckQuestsItemUpdate(item);
  6251. if (quest_updates) {
  6252. for (int32 i = 0; i < quest_updates->size(); i++)
  6253. SendQuestUpdate(quest_updates->at(i));
  6254. }
  6255. safe_delete(quest_updates);
  6256. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  6257. if (quest_failures) {
  6258. for (int32 i = 0; i < quest_failures->size(); i++)
  6259. SendQuestFailure(quest_failures->at(i));
  6260. }
  6261. safe_delete(quest_failures);
  6262. }
  6263. void Client::CheckPlayerQuestsLocationUpdate() {
  6264. vector<Quest*>* quest_updates = player->CheckQuestsLocationUpdate();
  6265. if (quest_updates) {
  6266. for (int32 i = 0; i < quest_updates->size(); i++)
  6267. SendQuestUpdate(quest_updates->at(i));
  6268. }
  6269. safe_delete(quest_updates);
  6270. }
  6271. void Client::CheckPlayerQuestsSpellUpdate(Spell* spell) {
  6272. vector<Quest*>* quest_updates = player->CheckQuestsSpellUpdate(spell);
  6273. if (quest_updates) {
  6274. for (int32 i = 0; i < quest_updates->size(); i++)
  6275. SendQuestUpdate(quest_updates->at(i));
  6276. }
  6277. safe_delete(quest_updates);
  6278. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  6279. if (quest_failures) {
  6280. for (int32 i = 0; i < quest_failures->size(); i++)
  6281. SendQuestFailure(quest_failures->at(i));
  6282. }
  6283. safe_delete(quest_failures);
  6284. }
  6285. void Client::AddPendingQuest(Quest* quest, bool forced) {
  6286. if (version <= 372 || forced) { //this client doesn't ask if you want the quest, so auto accept
  6287. MPendingQuestAccept.lock();
  6288. player->pending_quests[quest->GetQuestID()] = quest;
  6289. MPendingQuestAccept.unlock();
  6290. AcceptQuest(quest->GetQuestID());
  6291. }
  6292. else {
  6293. MPendingQuestAccept.lock();
  6294. player->pending_quests[quest->GetQuestID()] = quest;
  6295. MPendingQuestAccept.unlock();
  6296. EQ2Packet* outapp = quest->OfferQuest(GetVersion(), player);
  6297. //DumpPacket(outapp);
  6298. QueuePacket(outapp);
  6299. }
  6300. }
  6301. void Client::AcceptQuest(int32 quest_id) {
  6302. MPendingQuestAccept.lock_shared();
  6303. if (player->pending_quests.count(quest_id) > 0) {
  6304. Quest* quest = player->pending_quests[quest_id];
  6305. if (quest) {
  6306. MPendingQuestAccept.unlock_shared();
  6307. MPendingQuestAccept.lock();
  6308. player->pending_quests.erase(quest->GetQuestID());
  6309. MPendingQuestAccept.unlock();
  6310. AddPlayerQuest(quest);
  6311. GetCurrentZone()->SendQuestUpdates(this);
  6312. GetPlayer()->UpdateQuestCompleteCount(quest_id);
  6313. return; // already unlocked mutex
  6314. }
  6315. }
  6316. MPendingQuestAccept.unlock_shared();
  6317. }
  6318. void Client::RemovePendingQuest(int32 quest_id) {
  6319. bool send_updates = false;
  6320. MPendingQuestAccept.lock_shared();
  6321. if (player->pending_quests.count(quest_id) > 0) {
  6322. Quest* quest = player->pending_quests[quest_id];
  6323. MPendingQuestAccept.unlock_shared();
  6324. MPendingQuestAccept.lock();
  6325. player->pending_quests.erase(quest_id);
  6326. MPendingQuestAccept.unlock();
  6327. if (lua_interface) {
  6328. lua_interface->CallQuestFunction(quest, "Declined", GetPlayer());
  6329. lua_interface->SetLuaUserDataStale(quest);
  6330. }
  6331. safe_delete(quest);
  6332. send_updates = true;
  6333. }
  6334. else {
  6335. MPendingQuestAccept.unlock_shared();
  6336. }
  6337. if (send_updates) {
  6338. GetCurrentZone()->SendQuestUpdates(this);
  6339. }
  6340. }
  6341. void Client::SetPlayerQuest(Quest* quest, map<int32, int32>* progress) {
  6342. if (!quest || !progress) {
  6343. return;
  6344. }
  6345. map<int32, int32>::iterator itr;
  6346. QuestStep* step = 0;
  6347. for (itr = progress->begin(); itr != progress->end(); itr++) {
  6348. step = quest->GetQuestStep(itr->first);
  6349. if (step && itr->second > 0) {
  6350. step->SetStepProgress(itr->second);
  6351. if (lua_interface && step->GetQuestCurrentQuantity() >= step->GetQuestNeededQuantity())
  6352. lua_interface->CallQuestFunction(quest, "Reload", player, step->GetStepID());
  6353. }
  6354. }
  6355. if (lua_interface && step)
  6356. lua_interface->CallQuestFunction(quest, "CurrentStep", player, step->GetStepID());
  6357. else if (!step) {
  6358. LogWrite(QUEST__ERROR, 0, "Client", "Missing step for quest %s (ID %u), cannot CallQuestFunction for CurrentStep", quest->GetName(), quest->GetQuestID());
  6359. }
  6360. }
  6361. void Client::AddPlayerQuest(Quest* quest, bool call_accepted, bool send_packets) {
  6362. bool lockCleared = false;
  6363. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  6364. if (player->player_quests.count(quest->GetQuestID()) > 0 && player->player_quests[quest->GetQuestID()]) {
  6365. if (player->player_quests[quest->GetQuestID()]->GetQuestFlags() > 0)
  6366. quest->SetQuestFlags(player->player_quests[quest->GetQuestID()]->GetQuestFlags());
  6367. int32 questID = quest->GetQuestID();
  6368. lockCleared = true;
  6369. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  6370. RemovePlayerQuest(questID, false, false);
  6371. }
  6372. player->player_quests[quest->GetQuestID()] = quest;
  6373. if (!lockCleared)
  6374. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  6375. quest->SetPlayer(player);
  6376. quest->SetSaveNeeded(true);
  6377. current_quest_id = quest->GetQuestID();
  6378. if (send_packets && quest->GetQuestGiver() > 0)
  6379. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  6380. if (lua_interface && call_accepted)
  6381. lua_interface->CallQuestFunction(quest, "Accepted", player);
  6382. if (send_packets) {
  6383. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6384. //SendQuestJournal();
  6385. SendQuestJournalUpdate(quest);
  6386. // sent twice to match live
  6387. quest->SetTracked(false);
  6388. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  6389. quest->SetTracked(true);
  6390. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  6391. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  6392. }
  6393. //This isn't during a load screen, so update spawns with required quests
  6394. if (call_accepted)
  6395. player->SendQuestRequiredSpawns(quest->GetQuestID());
  6396. }
  6397. void Client::RemovePlayerQuest(int32 id, bool send_update, bool delete_quest) {
  6398. if (current_quest_id == id)
  6399. current_quest_id = 0;
  6400. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  6401. if (player->player_quests.count(id) > 0 && player->player_quests[id]) {
  6402. if (delete_quest) {
  6403. player->player_quests[id]->SetDeleted(true);
  6404. database.DeleteCharacterQuest(id, GetCharacterID(), player->GetCompletedPlayerQuests()->count(id) > 0);
  6405. }
  6406. int32 quest_giver = player->player_quests[id]->GetQuestGiver();
  6407. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  6408. if (send_update && quest_giver > 0)
  6409. GetCurrentZone()->SendSpawnChangesByDBID(quest_giver, this, false, true);
  6410. if (send_update) {
  6411. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6412. SendQuestJournal(false, 0, true);
  6413. }
  6414. player->RemoveQuest(id, delete_quest);
  6415. if (send_update) {
  6416. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6417. SendQuestJournal(false, 0, true);
  6418. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  6419. }
  6420. }
  6421. else {
  6422. // if we don't have any quests to count then release the write lock
  6423. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  6424. }
  6425. }
  6426. void Client::SendQuestUpdateStepImmediately(Quest* quest, int32 step, bool display_quest_helper) {
  6427. if (quest) {
  6428. QuestStep* quest_step = quest->GetQuestStep(step);
  6429. if (quest_step) {
  6430. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, quest_step, 1, false, false, display_quest_helper));
  6431. quest_step->WasUpdated(false);
  6432. }
  6433. }
  6434. }
  6435. void Client::SendQuestUpdateStep(Quest* quest, int32 step, bool display_quest_helper) {
  6436. QueuedQuest* item = new QueuedQuest;
  6437. item->quest_id = quest->GetQuestID();
  6438. item->step = step;
  6439. item->display_quest_helper = display_quest_helper;
  6440. MQuestQueue.writelock();
  6441. quest_queue.push_back(item);
  6442. last_update_time = Timer::GetCurrentTime2();
  6443. MQuestQueue.releasewritelock();
  6444. }
  6445. void Client::SendQuestFailure(Quest* quest) {
  6446. vector<QuestStep*>* failures = quest->GetQuestFailures();
  6447. if (failures) {
  6448. QuestStep* step = 0;
  6449. for (int32 i = 0; i < failures->size(); i++) {
  6450. step = failures->at(i);
  6451. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step, 1, false, true));
  6452. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6453. SendQuestJournal(false, 0, true);
  6454. }
  6455. failures->clear();
  6456. }
  6457. }
  6458. void Client::SendQuestUpdate(Quest* quest) {
  6459. vector<QuestStep*>* updates = quest->GetQuestUpdates();
  6460. if (updates) {
  6461. QuestStep* step = 0;
  6462. bool updated = false;
  6463. for (int32 i = 0; i < updates->size(); i++) {
  6464. step = updates->at(i);
  6465. if (lua_interface && step->Complete() && quest->GetCompleteAction(step->GetStepID()))
  6466. {
  6467. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(step->GetStepID()), player);
  6468. SendQuestUpdateStep(quest, step->GetStepID());
  6469. updated = true;
  6470. }
  6471. if (step->WasUpdated()) {
  6472. // reversing the order of SendQuestJournal and QueuePacket QuestJournalReply causes AoM client to crash!
  6473. SendQuestJournal(false, 0, true);
  6474. if (!updated)
  6475. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step));
  6476. updated = true;
  6477. }
  6478. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6479. }
  6480. if (lua_interface && quest->GetCompleted() && quest->GetCompleteAction()) {
  6481. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(), player);
  6482. SendQuestJournalUpdate(quest, true);
  6483. }
  6484. if (quest->GetCompleted()) {
  6485. if (quest->GetQuestReturnNPC() > 0)
  6486. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestReturnNPC(), this, false, true);
  6487. if (quest->GetCompletedFlag())
  6488. quest->SetCompletedFlag(false);
  6489. }
  6490. updates->clear();
  6491. }
  6492. }
  6493. void Client::SendQuestJournal(bool all_quests, Client* client, bool updated) {
  6494. if (!client)
  6495. client = this;
  6496. PacketStruct* packet = player->GetQuestJournalPacket(all_quests, GetVersion(), GetNameCRC(), current_quest_id, updated);
  6497. if (packet) {
  6498. EQ2Packet* outapp = packet->serialize();
  6499. //DumpPacket(outapp);
  6500. client->QueuePacket(outapp);
  6501. safe_delete(packet);
  6502. }
  6503. }
  6504. void Client::SendQuestJournalUpdate(Quest* quest, bool updated) {
  6505. PacketStruct* packet = player->GetQuestJournalPacket(quest, GetVersion(), GetNameCRC(), updated);
  6506. if (packet) {
  6507. QueuePacket(packet->serialize());
  6508. safe_delete(packet);
  6509. }
  6510. }
  6511. void Client::ReloadQuests() {
  6512. vector<int32> ids = player->GetQuestIDs();
  6513. Quest* quest = 0;
  6514. for (int32 i = 0; i < ids.size(); i++) {
  6515. quest = master_quest_list.GetQuest(ids[i]);
  6516. if (quest)
  6517. AddPlayerQuest(quest, false);
  6518. else
  6519. RemovePlayerQuest(ids[i]);
  6520. }
  6521. }
  6522. Quest* Client::GetPendingQuestAcceptance(int32 item_id) {
  6523. std::unique_lock lock(MPendingQuestAccept);
  6524. bool found_quest = false;
  6525. vector<int32>::iterator itr;
  6526. int32 questID = 0;
  6527. Quest* quest = nullptr;
  6528. for (itr = pending_quest_accept.begin(); itr != pending_quest_accept.end();) {
  6529. questID = *itr;
  6530. bool quest_exists = false;
  6531. quest = GetPlayer()->PendingQuestAcceptance(questID, item_id, &quest_exists);
  6532. if (!quest_exists) {
  6533. LogWrite(CCLIENT__ERROR, 0, "Client", "Quest ID %u missing for Player %s, removing quest id from pending_quest_accept.", questID, GetPlayer()->GetName());
  6534. itr = pending_quest_accept.erase(itr);
  6535. quest = nullptr;
  6536. continue;
  6537. }
  6538. else if (quest) {
  6539. pending_quest_accept.erase(itr);
  6540. break;
  6541. }
  6542. itr++;
  6543. }
  6544. return quest;
  6545. }
  6546. void Client::AcceptQuestReward(Quest* quest, int32 item_id) {
  6547. int8 num_slots_needed = 0;
  6548. int16 free_slots = player->item_list.GetNumberOfFreeSlots();
  6549. Item* master_item = 0;
  6550. if (item_id > 0) {
  6551. num_slots_needed++;
  6552. master_item = master_item_list.GetItem(item_id);
  6553. }
  6554. int32 totalItems = 0;
  6555. vector<Item*>* items = 0;
  6556. vector<Item*>* tmpItems = 0;
  6557. bool isTempState = quest->GetQuestTemporaryState();
  6558. if (isTempState)
  6559. {
  6560. tmpItems = quest->GetTmpRewardItems();
  6561. if (tmpItems && tmpItems->size() > 0)
  6562. {
  6563. num_slots_needed += tmpItems->size();
  6564. totalItems += tmpItems->size();
  6565. }
  6566. }
  6567. else
  6568. {
  6569. items = quest->GetRewardItems();
  6570. if (items && items->size() > 0)
  6571. {
  6572. num_slots_needed += items->size();
  6573. totalItems += items->size();
  6574. }
  6575. }
  6576. RemoveQueuedQuestReward();
  6577. GetPlayer()->SetActiveReward(false);
  6578. if (free_slots >= num_slots_needed || (player->item_list.HasFreeBagSlot() && master_item && master_item->IsBag() && master_item->bag_info->num_slots >= totalItems)) {
  6579. if (master_item)
  6580. AddItem(item_id);
  6581. if (tmpItems && tmpItems->size() > 0) {
  6582. for (int32 i = 0; i < tmpItems->size(); i++)
  6583. AddItem(new Item(tmpItems->at(i)));
  6584. }
  6585. if (items && items->size() > 0) {
  6586. for (int32 i = 0; i < items->size(); i++)
  6587. AddItem(new Item(items->at(i)));
  6588. }
  6589. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6590. if (outapp)
  6591. QueuePacket(outapp);
  6592. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  6593. map<int32, sint32>::iterator itr;
  6594. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  6595. int32 faction_id = itr->first;
  6596. sint32 amount = itr->second;
  6597. if (amount > 0)
  6598. player->GetFactions()->IncreaseFaction(faction_id, amount);
  6599. else
  6600. player->GetFactions()->DecreaseFaction(faction_id, (amount * -1));
  6601. }
  6602. if (quest->GetQuestTemporaryState())
  6603. {
  6604. int64 total_coins = quest->GetCoinTmpReward();
  6605. if (total_coins > 0)
  6606. AwardCoins(total_coins, std::string("for completing ").append(quest->GetName()));
  6607. player->GetInfoStruct()->add_status_points(quest->GetStatusTmpReward());
  6608. }
  6609. else {
  6610. player->GetInfoStruct()->add_status_points(quest->GetStatusPoints());
  6611. }
  6612. quest->SetQuestTemporaryState(false);
  6613. player->SetCharSheetChanged(true);
  6614. }
  6615. else {
  6616. GetPlayer()->SetActiveReward(true);
  6617. AddPendingQuestAcceptReward(quest);
  6618. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots! Free some slots and try again.");
  6619. DisplayQuestComplete(quest, quest->GetQuestTemporaryState(), quest->GetQuestTemporaryDescription());
  6620. }
  6621. }
  6622. 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) {
  6623. 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))) {
  6624. /*if (quest)
  6625. text = quest->GetName();
  6626. else*/
  6627. return;//nothing to give
  6628. }
  6629. GetPlayer()->ClearPendingSelectableItemRewards(0, true);
  6630. GetPlayer()->ClearPendingItemRewards();
  6631. PacketStruct* packet2 = configReader.getStruct("WS_QuestRewardPackMsg", GetVersion());
  6632. if (packet2) {
  6633. int32 source_id = 0;
  6634. if (quest)
  6635. source_id = quest->GetQuestID();
  6636. int64 rewarded_coin = 0;
  6637. if (quest) {
  6638. if (quest->GetCoinsReward() > 0) {
  6639. if (quest->GetCoinsRewardMax() > 0)
  6640. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  6641. else
  6642. rewarded_coin = quest->GetCoinsReward();
  6643. }
  6644. quest->SetGeneratedCoin(rewarded_coin);
  6645. }
  6646. if (rewarded_coin > coin)
  6647. coin = rewarded_coin;
  6648. 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
  6649. if (coin > 0) {
  6650. player->AddCoins(coin);
  6651. PlaySound("coin_cha_ching");
  6652. }
  6653. }
  6654. packet2->setSubstructDataByName("reward_data", "unknown1", 255);
  6655. packet2->setSubstructDataByName("reward_data", "reward", header);
  6656. packet2->setSubstructDataByName("reward_data", "max_coin", coin);
  6657. if (player->GetGuild() && !was_displayed) {
  6658. 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
  6659. player->GetInfoStruct()->add_status_points(status_points);
  6660. player->SetCharSheetChanged(true);
  6661. }
  6662. packet2->setSubstructDataByName("reward_data", "status_points", status_points);
  6663. }
  6664. if (text)
  6665. packet2->setSubstructDataByName("reward_data", "text", text);
  6666. std::vector<Item*> items;
  6667. quest->GetTmpRewardItemsByID(&items);
  6668. if (rewards || items.size() > 0) {
  6669. int32 item_count = items.size();
  6670. item_count += rewards ? rewards->size() : 0;
  6671. packet2->setSubstructArrayLengthByName("reward_data", "num_rewards", item_count);
  6672. int i = 0;
  6673. if (rewards) {
  6674. for (i = 0; i < rewards->size(); i++) {
  6675. Item* item = rewards->at(i);
  6676. if (item) {
  6677. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  6678. packet2->setItemArrayDataByName("item", item, player, i, 0, GetClientItemPacketOffset());
  6679. }
  6680. 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
  6681. player->AddPendingItemReward(item); //item reference will be deleted after the player accepts it
  6682. }
  6683. }
  6684. for (int j = 0; j < items.size(); j++) {
  6685. Item* item = items.at(j);
  6686. if (item) {
  6687. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  6688. packet2->setItemArrayDataByName("item", item, player, i, 0, GetClientItemPacketOffset());
  6689. }
  6690. 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
  6691. player->AddPendingItemReward(item); //item reference will be deleted after the player accepts it
  6692. i++;
  6693. }
  6694. }
  6695. if (selectable_rewards) {
  6696. packet2->setSubstructArrayLengthByName("reward_data", "num_select_rewards", selectable_rewards->size());
  6697. for (int i = 0; i < selectable_rewards->size(); i++) {
  6698. Item* item = selectable_rewards->at(i);
  6699. if (item) {
  6700. packet2->setArrayDataByName("select_reward_id", item->details.item_id, i);
  6701. packet2->setItemArrayDataByName("select_item", item, player, i, 0, GetClientItemPacketOffset());
  6702. 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
  6703. player->AddPendingSelectableItemReward(source_id, item); //item reference will be deleted after the player selects one
  6704. }
  6705. }
  6706. }
  6707. if (factions) {
  6708. map<int32, sint32>::iterator itr;
  6709. map<Faction*, signed int> factions_map;
  6710. for (itr = factions->begin(); itr != factions->end(); itr++) {
  6711. Faction* faction = master_faction_list.GetFaction(itr->first);
  6712. if (faction)
  6713. factions_map[faction] = itr->second;
  6714. }
  6715. packet2->setSubstructArrayLengthByName("reward_data", "num_factions", factions_map.size());
  6716. map<Faction*, signed int>::iterator faction_itr;
  6717. int8 i = 0;
  6718. for (faction_itr = factions_map.begin(); faction_itr != factions_map.end(); faction_itr++) {
  6719. packet2->setArrayDataByName("faction_name", faction_itr->first->name.c_str(), i);
  6720. sint32 amount = faction_itr->second;
  6721. packet2->setArrayDataByName("amount", amount, i);
  6722. if (!quest) { //this entire function is for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  6723. if (amount > 0)
  6724. player->GetFactions()->IncreaseFaction(faction_itr->first->id, amount);
  6725. else
  6726. player->GetFactions()->DecreaseFaction(faction_itr->first->id, (amount * -1));
  6727. }
  6728. i++;
  6729. }
  6730. }
  6731. QueuePacket(packet2->serialize());
  6732. safe_delete(packet2);
  6733. }
  6734. }
  6735. void Client::PopulateQuestRewardItems(vector <Item*>* items, PacketStruct* packet,
  6736. std::string num_rewards_str, std::string reward_id_str, std::string item_str) {
  6737. if (!items || !packet)
  6738. return;
  6739. if (items) {
  6740. int32 total_item_count = 0;
  6741. for (int s = 0; s < items->size(); s++) {
  6742. Item* tmpItem = items->at(s);
  6743. if (tmpItem) {
  6744. if (tmpItem->details.count > 1) {
  6745. total_item_count += tmpItem->details.count;
  6746. }
  6747. else {
  6748. total_item_count += 1;
  6749. }
  6750. }
  6751. }
  6752. packet->setArrayLengthByName(num_rewards_str.c_str(), total_item_count);
  6753. int16 count = 0;
  6754. int16 pos = 0;
  6755. for (int32 i = 0; i < items->size();) {
  6756. packet->setArrayDataByName(reward_id_str.c_str(), items->at(i)->details.item_id, pos);
  6757. if (version < 860)
  6758. packet->setItemArrayDataByName(item_str.c_str(), items->at(i), player, pos, 0, GetClientItemPacketOffset());
  6759. else if (version < 1193)
  6760. packet->setItemArrayDataByName(item_str.c_str(), items->at(i), player, pos);
  6761. else
  6762. packet->setItemArrayDataByName(item_str.c_str(), items->at(i), player, pos, 0, 2);
  6763. pos++;
  6764. if (count >= items->at(i)->details.count - 1) {
  6765. count = 0;
  6766. }
  6767. else if (items->at(i)->details.count > 1) {
  6768. count++;
  6769. continue;
  6770. }
  6771. i++;
  6772. }
  6773. }
  6774. }
  6775. void Client::DisplayQuestComplete(Quest* quest, bool tempReward, std::string customDescription, bool was_displayed) {
  6776. if (!quest)
  6777. return;
  6778. if (GetVersion() <= 561) {
  6779. DisplayQuestRewards(quest, 0, quest->GetRewardItems(), quest->GetSelectableRewardItems(), quest->GetRewardFactions(), "Quest Complete!", quest->GetStatusPoints(), tempReward ? customDescription.c_str() : quest->GetCompletedDescription(), was_displayed);
  6780. return;
  6781. }
  6782. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", GetVersion());
  6783. if (packet) {
  6784. packet->setDataByName("title", "Quest Reward!");
  6785. packet->setDataByName("name", quest->GetName());
  6786. if (tempReward)
  6787. {
  6788. packet->setDataByName("description", customDescription.c_str());
  6789. }
  6790. else
  6791. packet->setDataByName("description", quest->GetCompletedDescription());
  6792. packet->setDataByName("level", quest->GetLevel());
  6793. packet->setDataByName("encounter_level", quest->GetEncounterLevel());
  6794. int8 difficulty = 0;
  6795. if ((string)quest->GetType() == "Tradeskill")
  6796. difficulty = player->GetTSArrowColor(quest->GetLevel());
  6797. else
  6798. difficulty = player->GetArrowColor(quest->GetLevel());
  6799. packet->setDataByName("difficulty", difficulty);
  6800. if (tempReward)
  6801. {
  6802. packet->setDataByName("max_coin", quest->GetCoinTmpReward());
  6803. packet->setDataByName("min_coin", quest->GetCoinTmpReward());
  6804. packet->setDataByName("status_points", quest->GetStatusPoints());
  6805. }
  6806. else
  6807. {
  6808. int64 rewarded_coin = 0;
  6809. if (quest->GetCoinsReward() > 0) {
  6810. if (quest->GetCoinsRewardMax() > 0)
  6811. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  6812. else
  6813. rewarded_coin = quest->GetCoinsReward();
  6814. }
  6815. quest->SetGeneratedCoin(rewarded_coin);
  6816. packet->setDataByName("max_coin", rewarded_coin);
  6817. packet->setDataByName("min_coin", rewarded_coin);
  6818. packet->setDataByName("status_points", quest->GetStatusPoints());
  6819. }
  6820. if (tempReward) {
  6821. PopulateQuestRewardItems(quest->GetTmpRewardItems(), packet);
  6822. }
  6823. else
  6824. {
  6825. vector<Item*>* items2 = quest->GetSelectableRewardItems();
  6826. PopulateQuestRewardItems(quest->GetRewardItems(), packet);
  6827. PopulateQuestRewardItems(quest->GetSelectableRewardItems(), packet, std::string("num_select_rewards"),
  6828. std::string("select_reward_id"), std::string("select_item"));
  6829. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  6830. if (reward_factions && reward_factions->size() > 0) {
  6831. packet->setArrayLengthByName("num_factions", reward_factions->size());
  6832. map<int32, sint32>::iterator itr;
  6833. int16 index = 0;
  6834. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  6835. int32 faction_id = itr->first;
  6836. sint32 amount = itr->second;
  6837. const char* faction_name = master_faction_list.GetFactionNameByID(faction_id);
  6838. if (faction_name) {
  6839. packet->setArrayDataByName("faction_name", const_cast<char*>(faction_name), index);
  6840. packet->setArrayDataByName("amount", amount, index);
  6841. }
  6842. index++;
  6843. }
  6844. }
  6845. }
  6846. EQ2Packet* outapp = packet->serialize();
  6847. // DumpPacket(outapp);
  6848. QueuePacket(outapp);
  6849. safe_delete(packet);
  6850. }
  6851. }
  6852. void Client::DisplayRandomizeFeatures(int32 flags) {
  6853. SimpleMessage(CHANNEL_NARRATIVE, "Showing Active Randomize Features:");
  6854. if (flags > 0) {
  6855. if (flags & RANDOMIZE_GENDER)
  6856. SimpleMessage(CHANNEL_NARRATIVE, "- Gender");
  6857. if (flags & RANDOMIZE_RACE)
  6858. SimpleMessage(CHANNEL_NARRATIVE, "- Race");
  6859. if (flags & RANDOMIZE_MODEL_TYPE)
  6860. SimpleMessage(CHANNEL_NARRATIVE, "- Model");
  6861. if (flags & RANDOMIZE_FACIAL_HAIR_TYPE)
  6862. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair");
  6863. if (flags & RANDOMIZE_HAIR_TYPE)
  6864. SimpleMessage(CHANNEL_NARRATIVE, "- Hair");
  6865. if (flags & RANDOMIZE_WING_TYPE)
  6866. SimpleMessage(CHANNEL_NARRATIVE, "- Wing");
  6867. if (flags & RANDOMIZE_CHEEK_TYPE)
  6868. SimpleMessage(CHANNEL_NARRATIVE, "- Cheek");
  6869. if (flags & RANDOMIZE_CHIN_TYPE)
  6870. SimpleMessage(CHANNEL_NARRATIVE, "- Chin");
  6871. if (flags & RANDOMIZE_EAR_TYPE)
  6872. SimpleMessage(CHANNEL_NARRATIVE, "- Ear");
  6873. if (flags & RANDOMIZE_EYE_BROW_TYPE)
  6874. SimpleMessage(CHANNEL_NARRATIVE, "- Eyebrow");
  6875. if (flags & RANDOMIZE_EYE_TYPE)
  6876. SimpleMessage(CHANNEL_NARRATIVE, "- Eye");
  6877. if (flags & RANDOMIZE_LIP_TYPE)
  6878. SimpleMessage(CHANNEL_NARRATIVE, "- Lip");
  6879. if (flags & RANDOMIZE_NOSE_TYPE)
  6880. SimpleMessage(CHANNEL_NARRATIVE, "- Nose");
  6881. if (flags & RANDOMIZE_EYE_COLOR)
  6882. SimpleMessage(CHANNEL_NARRATIVE, "- Eye Color");
  6883. if (flags & RANDOMIZE_HAIR_COLOR1)
  6884. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color1");
  6885. if (flags & RANDOMIZE_HAIR_COLOR2)
  6886. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color2");
  6887. if (flags & RANDOMIZE_HAIR_HIGHLIGHT)
  6888. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color Highlights");
  6889. if (flags & RANDOMIZE_HAIR_FACE_COLOR)
  6890. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color");
  6891. if (flags & RANDOMIZE_HAIR_FACE_HIGHLIGHT_COLOR)
  6892. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color Highlights");
  6893. if (flags & RANDOMIZE_HAIR_TYPE_COLOR)
  6894. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Color");
  6895. if (flags & RANDOMIZE_HAIR_TYPE_HIGHLIGHT_COLOR)
  6896. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Highlights");
  6897. if (flags & RANDOMIZE_SKIN_COLOR)
  6898. SimpleMessage(CHANNEL_NARRATIVE, "- Skin Color");
  6899. if (flags & RANDOMIZE_WING_COLOR1)
  6900. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color1");
  6901. if (flags & RANDOMIZE_WING_COLOR2)
  6902. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color2");
  6903. }
  6904. else
  6905. {
  6906. SimpleMessage(CHANNEL_NARRATIVE, "- No Randomization Set.");
  6907. }
  6908. }
  6909. void Client::GiveQuestReward(Quest* quest, bool has_displayed) {
  6910. current_quest_id = 0;
  6911. if (!quest->GetQuestTemporaryState() && !has_displayed)
  6912. {
  6913. quest->IncrementCompleteCount();
  6914. player->AddCompletedQuest(quest);
  6915. }
  6916. AddPendingQuestAcceptReward(quest);
  6917. DisplayQuestComplete(quest, quest->GetQuestTemporaryState(), quest->GetQuestTemporaryDescription());
  6918. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6919. SendQuestJournal();
  6920. if (quest->GetQuestTemporaryState()) {
  6921. return;
  6922. }
  6923. if (!has_displayed) {
  6924. if (quest->GetExpReward() > 0) {
  6925. int32 xp = quest->GetExpReward();
  6926. player->AddXP(xp);
  6927. }
  6928. if (quest->GetTSExpReward() > 0) {
  6929. int8 ts_level = player->GetTSLevel();
  6930. int32 xp = quest->GetTSExpReward();
  6931. if (player->AddTSXP(xp)) {
  6932. Message(CHANNEL_REWARD, "You gain %u tradeskill experience!", (int32)xp);
  6933. if (player->GetTSLevel() != ts_level)
  6934. ChangeTSLevel(ts_level, player->GetTSLevel());
  6935. player->SetCharSheetChanged(true);
  6936. }
  6937. }
  6938. int64 total_coins = quest->GetGeneratedCoin();
  6939. if (total_coins > 0)
  6940. AwardCoins(total_coins, std::string("for completing ").append(quest->GetName()));
  6941. player->RemoveQuest(quest->GetQuestID(), false);
  6942. }
  6943. if (quest->GetQuestGiver() > 0)
  6944. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  6945. if (!has_displayed) {
  6946. RemovePlayerQuest(quest->GetQuestID(), true, false);
  6947. }
  6948. }
  6949. 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) {
  6950. std::unique_lock lock(MConversation);
  6951. PacketStruct* packet = configReader.getStruct("WS_DialogOpen", GetVersion());
  6952. if (packet) {
  6953. packet->setDataByName("conversation_id", conversation_id);
  6954. packet->setDataByName("text", text);
  6955. packet->setDataByName("language", language); // default 0
  6956. packet->setDataByName("enable_blue_ui", 0); // default 0
  6957. packet->setDataByName("can_close", can_close); // default 1
  6958. conversation_map[conversation_id].clear();
  6959. if (conversations) {
  6960. packet->setArrayLengthByName("num_responses", conversations->size());
  6961. for (int32 i = 0; i < conversations->size(); i++) {
  6962. packet->setArrayDataByName("response", conversations->at(i).option.c_str(), i);
  6963. if (conversations->at(i).function.length() > 0)
  6964. conversation_map[conversation_id][i] = conversations->at(i).function;
  6965. }
  6966. }
  6967. packet->setDataByName("spawn_id", spawn_id);
  6968. if (mp3) {
  6969. packet->setDataByName("voice", mp3);
  6970. packet->setDataByName("key1", key1);
  6971. packet->setDataByName("key2", key2);
  6972. }
  6973. QueuePacket(packet->serialize());
  6974. safe_delete(packet);
  6975. }
  6976. }
  6977. 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) {
  6978. if (!item || !text || !conversations || conversations->size() == 0) {
  6979. return;
  6980. }
  6981. int32 conversation_id = GetConversationID(0, item);
  6982. if (conversation_id == 0) {
  6983. next_conversation_id++;
  6984. conversation_id = next_conversation_id;
  6985. }
  6986. MConversation.lock();
  6987. conversation_items[conversation_id] = item;
  6988. MConversation.unlock();
  6989. if (type == 4)
  6990. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2, language, can_close);
  6991. else
  6992. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2, language, can_close);
  6993. }
  6994. 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) {
  6995. if (!src || !(type == 1 || type == 2 || type == 3) || !text /*|| !conversations || conversations->size() == 0*/) {
  6996. return;
  6997. }
  6998. int32 conversation_id = GetConversationID(src, 0);
  6999. if (conversation_id == 0) {
  7000. next_conversation_id++;
  7001. conversation_id = next_conversation_id;
  7002. }
  7003. MConversation.lock();
  7004. conversation_spawns[conversation_id] = src->GetID();
  7005. MConversation.unlock();
  7006. /* Spawns can start two different types of conversations.
  7007. * Type 1: The chat type with bubbles.
  7008. * Type 2: The dialog type with the blue box. */
  7009. if (type == 1)
  7010. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(src), conversations, text, mp3, key1, key2, language, can_close);
  7011. else if (type == 2)
  7012. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2, language, can_close);
  7013. else //if (type == 3)
  7014. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2, language, can_close);
  7015. }
  7016. void Client::CloseDialog(int32 conversation_id) {
  7017. std::unique_lock lock(MConversation);
  7018. PacketStruct* packet = configReader.getStruct("WS_ServerDialogClose", GetVersion());
  7019. if (packet) {
  7020. packet->setDataByName("conversation_id", conversation_id);
  7021. QueuePacket(packet->serialize());
  7022. safe_delete(packet);
  7023. }
  7024. std::map<int32, Item*>::iterator itr;
  7025. while ((itr = conversation_items.find(conversation_id)) != conversation_items.end())
  7026. {
  7027. conversation_items.erase(itr);
  7028. }
  7029. std::map<int32, int32>::iterator itr2 = conversation_spawns.find(conversation_id);
  7030. while ((itr2 = conversation_spawns.find(conversation_id)) != conversation_spawns.end())
  7031. {
  7032. conversation_spawns.erase(itr2);
  7033. }
  7034. }
  7035. int32 Client::GetConversationID(Spawn* spawn, Item* item) {
  7036. std::shared_lock lock(MConversation);
  7037. int32 conversation_id = 0;
  7038. if (spawn) {
  7039. map<int32, int32>::iterator itr;
  7040. for (itr = conversation_spawns.begin(); itr != conversation_spawns.end(); itr++) {
  7041. if (itr->second == spawn->GetID()) {
  7042. conversation_id = itr->first;
  7043. break;
  7044. }
  7045. }
  7046. }
  7047. else if (item) {
  7048. map<int32, Item*>::iterator itr;
  7049. for (itr = conversation_items.begin(); itr != conversation_items.end(); itr++) {
  7050. if (itr->second == item) {
  7051. conversation_id = itr->first;
  7052. break;
  7053. }
  7054. }
  7055. }
  7056. return conversation_id;
  7057. }
  7058. Spawn* Client::GetCombineSpawn() {
  7059. return combine_spawn;
  7060. }
  7061. bool Client::ShouldTarget() {
  7062. return should_target;
  7063. }
  7064. void Client::TargetSpawn(Spawn* spawn) {
  7065. should_target = false;
  7066. PacketStruct* packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  7067. if (packet) {
  7068. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  7069. QueuePacket(packet->serialize());
  7070. safe_delete(packet);
  7071. }
  7072. GetPlayer()->SetTarget(spawn);
  7073. GetPlayer()->info_changed = true;
  7074. GetPlayer()->changed = true;
  7075. GetPlayer()->AddChangedZoneSpawn();
  7076. }
  7077. void Client::CombineSpawns(float radius, Spawn* spawn) {
  7078. combine_spawn = spawn;
  7079. spawn->RemoveSpawnFromGroup(true);
  7080. if (!GetCurrentZone()->AddCloseSpawnsToSpawnGroup(combine_spawn, radius))
  7081. SimpleMessage(CHANNEL_COLOR_YELLOW, "One or more spawns are in a spawn group and cannot be combined until they are removed from their group.");
  7082. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  7083. should_target = true;
  7084. }
  7085. void Client::AddCombineSpawn(Spawn* spawn) {
  7086. if (combine_spawn && combine_spawn != spawn && spawn) {
  7087. combine_spawn->AddSpawnToGroup(spawn);
  7088. spawn->AddSpawnToGroup(combine_spawn);
  7089. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  7090. }
  7091. else if (spawn)
  7092. combine_spawn = spawn;
  7093. should_target = true;
  7094. }
  7095. void Client::RemoveCombineSpawn(Spawn* spawn) {
  7096. if (combine_spawn && spawn)
  7097. spawn->RemoveSpawnFromGroup();
  7098. if (combine_spawn == spawn)
  7099. combine_spawn->RemoveSpawnFromGroup(true);
  7100. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  7101. if (combine_spawn == spawn)
  7102. combine_spawn = 0;
  7103. }
  7104. void Client::SaveCombineSpawns(const char* name) {
  7105. if (!combine_spawn) {
  7106. return;
  7107. }
  7108. vector<Spawn*>* spawns = combine_spawn->GetSpawnGroup();
  7109. if (!spawns) {
  7110. return;
  7111. }
  7112. int32 count = spawns->size();
  7113. int32 spawnLocationID = 0;
  7114. if (count == 1)
  7115. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error: You only have a single Spawn in the group!");
  7116. else if ((spawnLocationID = database.SaveCombinedSpawnLocation(GetCurrentZone(), combine_spawn, name)) > 0) {
  7117. Message(CHANNEL_COLOR_YELLOW, "Successfully combined %u spawns into spawn location: %u", count, spawnLocationID);
  7118. // we remove the spawn inside SaveCombinedSpawnLocation
  7119. //GetCurrentZone()->RemoveSpawn(combine_spawn);
  7120. }
  7121. else
  7122. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn group, check console for details.");
  7123. safe_delete(spawns);
  7124. combine_spawn = 0;
  7125. }
  7126. bool Client::AddItem(int32 item_id, int16 quantity, AddItemType type) {
  7127. Item* master_item = master_item_list.GetItem(item_id);
  7128. Item* item = 0;
  7129. if (master_item)
  7130. item = new Item(master_item);
  7131. if (item) {
  7132. if (quantity > 0)
  7133. item->details.count = quantity;
  7134. return AddItem(item, nullptr, type);
  7135. }
  7136. else
  7137. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  7138. return false;
  7139. }
  7140. bool Client::AddItem(Item* item, bool* item_deleted, AddItemType type) {
  7141. if (!item) {
  7142. return false;
  7143. }
  7144. if (player->AddItem(item, type)) {
  7145. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  7146. if (outapp) {
  7147. //DumpPacket(outapp);
  7148. QueuePacket(outapp);
  7149. //resend bag desc with new item name added
  7150. outapp = player->SendBagUpdate(item->details.unique_id, GetVersion());
  7151. if (outapp) {
  7152. //DumpPacket(outapp);
  7153. QueuePacket(outapp);
  7154. }
  7155. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  7156. DumpPacket(app);
  7157. client->QueuePacket(app);
  7158. */
  7159. }
  7160. CheckPlayerQuestsItemUpdate(item);
  7161. if (item->GetItemScript() && lua_interface)
  7162. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  7163. }
  7164. else {
  7165. lua_interface->SetLuaUserDataStale(item);
  7166. // likely lore conflict
  7167. if (item_deleted)
  7168. *item_deleted = true;
  7169. return false;
  7170. }
  7171. return true;
  7172. }
  7173. bool Client::AddItemToBank(int32 item_id, int16 quantity) {
  7174. Item* master_item = master_item_list.GetItem(item_id);
  7175. Item* item = 0;
  7176. if (master_item)
  7177. item = new Item(master_item);
  7178. if (item) {
  7179. if (quantity > 0)
  7180. item->details.count = quantity;
  7181. return AddItemToBank(item);
  7182. }
  7183. else
  7184. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  7185. return false;
  7186. }
  7187. bool Client::AddItemToBank(Item* item) {
  7188. if (!item) {
  7189. return false;
  7190. }
  7191. if (player->AddItemToBank(item)) {
  7192. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  7193. if (outapp) {
  7194. QueuePacket(outapp);
  7195. //resend bag desc with new item name added
  7196. outapp = player->SendBagUpdate(item->details.inv_slot_id, GetVersion());
  7197. if (outapp)
  7198. QueuePacket(outapp);
  7199. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  7200. DumpPacket(app);
  7201. client->QueuePacket(app);
  7202. */
  7203. }
  7204. CheckPlayerQuestsItemUpdate(item);
  7205. if (item->GetItemScript() && lua_interface)
  7206. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  7207. }
  7208. else {
  7209. lua_interface->SetLuaUserDataStale(item);
  7210. // likely lore conflict
  7211. safe_delete(item);
  7212. return false;
  7213. }
  7214. return true;
  7215. }
  7216. void Client::UnequipItem(int16 index, sint32 bag_id, int8 to_slot, int8 appearance_equip) {
  7217. vector<EQ2Packet*> packets = GetPlayer()->UnequipItem(index, bag_id, to_slot, GetVersion(), appearance_equip);
  7218. EQ2Packet* outapp = 0;
  7219. for (int32 i = 0; i < packets.size(); i++)
  7220. {
  7221. outapp = packets[i];
  7222. if (outapp)
  7223. QueuePacket(outapp);
  7224. }
  7225. GetPlayer()->UpdateWeapons();
  7226. EQ2Packet* characterSheetPackets = GetPlayer()->GetPlayerInfo()->serialize(GetVersion());
  7227. QueuePacket(characterSheetPackets);
  7228. }
  7229. bool Client::RemoveItem(Item* item, int16 quantity, bool force_override_no_delete) {
  7230. EQ2Packet* outapp;
  7231. bool delete_item = false;
  7232. assert(item);
  7233. if (quantity > 0 && !item->IsBag() && item->details.count > quantity) {
  7234. item->details.count -= quantity;
  7235. item->save_needed = true;
  7236. }
  7237. else {
  7238. database.DeleteItem(character_id, item, 0);
  7239. player->GetPlayerItemList()->RemoveItem(item, false);
  7240. delete_item = true;
  7241. }
  7242. if (force_override_no_delete)
  7243. delete_item = false;
  7244. if ((outapp = player->SendInventoryUpdate(version))) {
  7245. QueuePacket(outapp);
  7246. if (item->GetItemScript() && lua_interface)
  7247. lua_interface->RunItemScript(item->GetItemScript(), "removed", item, player);
  7248. if (delete_item)
  7249. {
  7250. PurgeItem(item);
  7251. lua_interface->SetLuaUserDataStale(item);
  7252. safe_delete(item);
  7253. }
  7254. GetPlayer()->CalculateApplyWeight();
  7255. return true;
  7256. }
  7257. return false;
  7258. }
  7259. void Client::SetLuaDebugClient(bool val) {
  7260. if (val)
  7261. lua_debug_timer.Start();
  7262. lua_debug = val;
  7263. if (lua_interface && !val) {
  7264. lua_interface->RemoveDebugClients(this);
  7265. lua_debug_timer.Disable();
  7266. }
  7267. }
  7268. void Client::SetMerchantTransaction(Spawn* spawn) {
  7269. merchant_transaction = spawn;
  7270. }
  7271. Spawn* Client::GetMerchantTransaction() {
  7272. return merchant_transaction;
  7273. }
  7274. void Client::SetMailTransaction(Spawn* spawn) {
  7275. ResetSendMail(spawn ? false : true);
  7276. MMailWindowMutex.lock();
  7277. mail_transaction = spawn;
  7278. MMailWindowMutex.unlock();
  7279. }
  7280. Spawn* Client::GetMailTransaction() {
  7281. return mail_transaction;
  7282. }
  7283. void Client::PlaySound(const char* name) {
  7284. if (name) {
  7285. PacketStruct* packet = configReader.getStruct("WS_PlaySound", GetVersion());
  7286. if (packet) {
  7287. packet->setMediumStringByName("name", name);
  7288. QueuePacket(packet->serialize());
  7289. safe_delete(packet);
  7290. }
  7291. }
  7292. }
  7293. float Client::CalculateBuyMultiplier(int32 merchant_id) {
  7294. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  7295. if(multiplier){
  7296. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  7297. float diff_low = faction_val - multiplier->faction_min;
  7298. if(diff_low < 0)
  7299. diff_low*=-1;
  7300. float total_diff = multiplier->faction_max - multiplier->faction_min;
  7301. if(total_diff < 0)
  7302. total_diff*=-1;
  7303. float buy_multiplier = multiplier->high_buy_multiplier - multiplier->low_buy_multiplier;
  7304. float total1 = (diff_low/total_diff);
  7305. float final_buy_multiplier = total1*buy_multiplier + total1*multiplier->low_buy_multiplier;
  7306. return final_buy_multiplier;
  7307. }*/
  7308. return 1;
  7309. }
  7310. float Client::CalculateSellMultiplier(int32 merchant_id) {
  7311. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  7312. if(multiplier){
  7313. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  7314. float diff_low = faction_val - multiplier->faction_min;
  7315. if(diff_low < 0)
  7316. diff_low*=-1;
  7317. float total_diff = multiplier->faction_max - multiplier->faction_min;
  7318. if(total_diff < 0)
  7319. total_diff*=-1;
  7320. float sell_multiplier = multiplier->high_sell_multiplier - multiplier->low_sell_multiplier;
  7321. float total1 = (diff_low/total_diff);
  7322. float final_sell_multiplier = total1*sell_multiplier + total1*multiplier->low_sell_multiplier;
  7323. return final_sell_multiplier;
  7324. }*/
  7325. return 1;
  7326. }
  7327. void Client::SellItem(int32 item_id, int16 quantity, int32 unique_id) {
  7328. Spawn* spawn = GetMerchantTransaction();
  7329. Guild* guild = GetPlayer()->GetGuild();
  7330. if (spawn && spawn->GetMerchantID() > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY)) &&
  7331. spawn->IsClientInMerchantLevelRange(this)) {
  7332. int32 total_sell_price = 0;
  7333. int32 total_status_sell_price = 0; //for status
  7334. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  7335. int32 sell_price = 0;
  7336. int32 status_sell_price = 0; //for status
  7337. Item* master_item = master_item_list.GetItem(item_id);
  7338. Item* item = 0;
  7339. if (unique_id == 0)
  7340. item = player->item_list.GetItemFromID(item_id, quantity);
  7341. else
  7342. item = player->item_list.GetItemFromUniqueID(unique_id);
  7343. if (!item)
  7344. item = player->item_list.GetItemFromID(item_id);
  7345. if (item && master_item) {
  7346. if (item->details.item_locked || item->details.equip_slot_id)
  7347. {
  7348. SimpleMessage(CHANNEL_COLOR_RED, "You cannot sell the item in use.");
  7349. return;
  7350. }
  7351. else if (item->CheckFlag(NO_VALUE))
  7352. {
  7353. SimpleMessage(CHANNEL_COLOR_RED, "This item has no value.");
  7354. return;
  7355. }
  7356. else if (item->IsBag())
  7357. {
  7358. int32 bagitemcount = player->GetPlayerItemList()->GetItemCountInBag(item);
  7359. if (bagitemcount > 0) {
  7360. SimpleMessage(CHANNEL_COLOR_RED, "You cannot sell a bag with items inside it.");
  7361. return;
  7362. }
  7363. }
  7364. int32 sell_price = (int32)(master_item->sell_price * multiplier);
  7365. if (sell_price > item->sell_price)
  7366. sell_price = item->sell_price;
  7367. if (quantity > item->details.count)
  7368. quantity = item->details.count;
  7369. total_sell_price = sell_price * quantity;
  7370. //------------------------------For Selling Status Items
  7371. status_sell_price = (int32)(master_item->sell_status * multiplier);
  7372. if (status_sell_price > item->sell_status)
  7373. status_sell_price = item->sell_status;
  7374. if (quantity > item->details.count)
  7375. quantity = item->details.count;
  7376. total_status_sell_price = status_sell_price * quantity;
  7377. if (total_status_sell_price > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))
  7378. total_status_sell_price = 0;
  7379. player->GetInfoStruct()->add_status_points(total_status_sell_price);
  7380. int32 guildMaxLevel = 5 + item->details.recommended_level; // client hard codes +5 to the level
  7381. if (player->GetGuild() && guild->GetLevel() < guildMaxLevel) {
  7382. guild->UpdateGuildStatus(GetPlayer(), total_status_sell_price / 10);
  7383. guild->SendGuildMemberList();
  7384. guild->AddEXPCurrent((total_status_sell_price / 10), true);
  7385. }
  7386. if (quantity > 1)
  7387. {
  7388. if (total_status_sell_price)
  7389. 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);
  7390. else
  7391. 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());
  7392. }
  7393. else
  7394. {
  7395. if (total_status_sell_price)
  7396. 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);
  7397. else
  7398. 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());
  7399. }
  7400. player->AddCoins(total_sell_price);
  7401. if (!item->no_buy_back && (total_status_sell_price == 0 || (total_status_sell_price > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))))
  7402. AddBuyBack(unique_id, item_id, quantity, sell_price);
  7403. if (quantity >= item->details.count) {
  7404. database.DeleteItem(GetCharacterID(), item, 0);
  7405. player->item_list.RemoveItem(item, true);
  7406. }
  7407. else {
  7408. item->details.count -= quantity;
  7409. item->save_needed = true;
  7410. }
  7411. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  7412. if (outapp)
  7413. QueuePacket(outapp);
  7414. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  7415. SendBuyBackList();
  7416. }
  7417. }
  7418. }
  7419. void Client::BuyBack(int32 item_id, int16 quantity) {
  7420. Spawn* spawn = GetMerchantTransaction();
  7421. if (spawn && spawn->GetMerchantID() > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK)) &&
  7422. spawn->IsClientInMerchantLevelRange(this)) {
  7423. deque<BuyBackItem*>::iterator itr;
  7424. BuyBackItem* buyback = 0;
  7425. BuyBackItem* closest = 0;
  7426. MBuyBack.readlock(__FUNCTION__, __LINE__);
  7427. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  7428. buyback = *itr;
  7429. if (buyback->unique_id == item_id) {
  7430. closest = buyback;
  7431. quantity = buyback->quantity;
  7432. break;
  7433. }
  7434. }
  7435. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  7436. if (closest) {
  7437. Item* item = 0;
  7438. Item* master_item = master_item_list.GetItem(closest->item_id);
  7439. if (master_item) {
  7440. item = new Item(master_item);
  7441. if (closest->quantity >= quantity)
  7442. item->details.count = quantity;
  7443. else
  7444. item->details.count = closest->quantity;
  7445. }
  7446. bool itemDeleted = false;
  7447. bool itemAdded = false;
  7448. sint64 dispFlags = 0;
  7449. if (item && item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "buyback_display_flags", item, player, nullptr, &dispFlags) && (dispFlags & DISPLAY_FLAG_NO_BUY))
  7450. SimpleMessage(CHANNEL_NARRATIVE, "You do not meet all the requirements to buy this item.");
  7451. else if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item))
  7452. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  7453. else if (player->RemoveCoins(closest->quantity * closest->price)) {
  7454. bool removed = false;
  7455. if (closest->quantity == quantity) {
  7456. MBuyBack.writelock(__FUNCTION__, __LINE__);
  7457. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  7458. if (*itr == closest) {
  7459. buy_back_items.erase(itr);
  7460. removed = true;
  7461. break;
  7462. }
  7463. }
  7464. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  7465. }
  7466. else {
  7467. closest->quantity -= quantity;
  7468. closest->save_needed = true;
  7469. }
  7470. itemAdded = AddItem(item, &itemDeleted);
  7471. if (removed) {
  7472. database.DeleteBuyBack(GetCharacterID(), closest->item_id, closest->quantity, closest->price);
  7473. safe_delete(closest);
  7474. }
  7475. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  7476. SendBuyBackList();
  7477. }
  7478. else
  7479. SimpleMessage(CHANNEL_COLOR_RED, "You cannot afford this item.");
  7480. if (!itemAdded && !itemDeleted) {
  7481. lua_interface->SetLuaUserDataStale(item);
  7482. safe_delete(item);
  7483. }
  7484. }
  7485. }
  7486. }
  7487. void Client::BuyItem(int32 item_id, int16 quantity) {
  7488. // Get the merchant we are buying from
  7489. Spawn* spawn = GetMerchantTransaction();
  7490. // Make sure the spawn has a merchant list
  7491. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  7492. int32 total_buy_price = 0;
  7493. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  7494. int32 sell_price = 0;
  7495. Item* master_item = master_item_list.GetItem(item_id);
  7496. Item* item = 0;
  7497. int16 total_available = 0;
  7498. vector<MerchantItemInfo>* temp;
  7499. vector<MerchantItemInfo>::iterator itr;
  7500. MerchantItemInfo* ItemInfo = 0;
  7501. temp = world.GetMerchantList(spawn->GetMerchantID());
  7502. for (itr = temp->begin(); itr != temp->end(); itr++) {
  7503. if ((*itr).item_id == item_id) {
  7504. ItemInfo = &(*itr);
  7505. break;
  7506. }
  7507. }
  7508. if (master_item && ItemInfo) {
  7509. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO) {
  7510. quantity = 1;
  7511. total_available = 0xFFFF;
  7512. sell_price = master_item->sell_price;
  7513. }
  7514. else {
  7515. total_available = world.GetMerchantItemQuantity(spawn->GetMerchantID(), item_id);
  7516. sell_price = (int32)(master_item->sell_price * multiplier);
  7517. if (quantity > total_available)
  7518. quantity = total_available;
  7519. }
  7520. sint64 dispFlags = 0;
  7521. 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))
  7522. {
  7523. SimpleMessage(CHANNEL_NARRATIVE, "You do not meet all the requirements to buy this item.");
  7524. return;
  7525. }
  7526. if (quantity < 1)
  7527. {
  7528. SimpleMessage(CHANNEL_COLOR_RED, "Merchant does not have item for purchase (quantity < 1).");
  7529. return;
  7530. }
  7531. total_buy_price = sell_price * quantity;
  7532. item = new Item(master_item);
  7533. item->details.count = quantity;
  7534. if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item)) {
  7535. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  7536. lua_interface->SetLuaUserDataStale(item);
  7537. safe_delete(item);
  7538. }
  7539. else {
  7540. // Price not set in the merchant_inventory table, use the old method
  7541. if (ItemInfo->price_item_id == 0 && ItemInfo->price_item2_id == 0 && ItemInfo->price_status == 0 && ItemInfo->price_stationcash == 0 && ItemInfo->price_coins == 0) {
  7542. if (player->RemoveCoins(total_buy_price)) {
  7543. item->SetMaxSellValue(sell_price);
  7544. if (quantity > 1)
  7545. 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());
  7546. else
  7547. 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());
  7548. bool itemDeleted = false;
  7549. AddItem(item, &itemDeleted);
  7550. if (!itemDeleted) {
  7551. CheckPlayerQuestsItemUpdate(item);
  7552. if (item && total_available < 0xFF) {
  7553. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  7554. SendBuyMerchantList();
  7555. }
  7556. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  7557. PlayLotto(total_buy_price, item->details.item_id);
  7558. }
  7559. }
  7560. else {
  7561. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  7562. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  7563. PlaySound("buy_failed");
  7564. }
  7565. }
  7566. else {
  7567. // Price set in merchant_inventory table
  7568. // Check if the player has enough status, coins and staion cash to buy the item before checking the items
  7569. // TODO: need to add support for station cash
  7570. if (player->GetInfoStruct()->get_status_points() >= (ItemInfo->price_status * quantity) && player->HasCoins(ItemInfo->price_coins * quantity)) {
  7571. // Check items
  7572. int16 item_quantity = 0;
  7573. // Default these to true in case price_item_id or price_item2_id was never set
  7574. bool hasItem1 = true;
  7575. bool hasItem2 = true;
  7576. Item* tempItem1 = 0;
  7577. Item* tempItem2 = 0;
  7578. if (ItemInfo->price_item_id != 0) {
  7579. // Same item for whatever reason lets add the quantities together
  7580. if (ItemInfo->price_item_id == ItemInfo->price_item2_id)
  7581. item_quantity = ItemInfo->price_item_qty + ItemInfo->price_item2_qty;
  7582. else
  7583. item_quantity = ItemInfo->price_item_qty;
  7584. tempItem1 = player->item_list.GetItemFromID(ItemInfo->price_item_id);
  7585. if (tempItem1) {
  7586. if (tempItem1->details.count < item_quantity)
  7587. hasItem1 = false;
  7588. }
  7589. else {
  7590. hasItem1 = false;
  7591. }
  7592. }
  7593. // Check item2, if item_quantity is greater then item1 quantity then item2 is the same item
  7594. // as item1 and we already checked for it so we can skip this check
  7595. if (ItemInfo->price_item2_id != 0 && item_quantity <= ItemInfo->price_item_qty) {
  7596. tempItem2 = player->item_list.GetItemFromID(ItemInfo->price_item2_id);
  7597. if (tempItem2) {
  7598. if (tempItem2->details.count < ItemInfo->price_item2_qty)
  7599. hasItem2 = false;
  7600. }
  7601. else {
  7602. hasItem2 = false;
  7603. }
  7604. }
  7605. // if we have every thing then remove the price and give the item
  7606. if (hasItem1 && hasItem2) {
  7607. player->GetInfoStruct()->set_status_points(player->GetInfoStruct()->get_status_points() - (ItemInfo->price_status * quantity));
  7608. // TODO: station cash
  7609. // The update that would normally be sent after modifing the players inventory is automatically sent in AddItem wich is called later
  7610. // so there is no need to send it more then that one time
  7611. if (tempItem1) {
  7612. if (tempItem1->details.count > item_quantity) {
  7613. tempItem1->details.count -= item_quantity;
  7614. tempItem1->save_needed = true;
  7615. }
  7616. else {
  7617. database.DeleteItem(GetCharacterID(), tempItem1, 0);
  7618. player->item_list.DestroyItem(tempItem1->details.index);
  7619. }
  7620. }
  7621. if (tempItem2) {
  7622. if (tempItem2->details.count > ItemInfo->price_item2_qty) {
  7623. tempItem2->details.count -= ItemInfo->price_item2_qty;
  7624. tempItem2->save_needed = true;
  7625. }
  7626. else {
  7627. database.DeleteItem(GetCharacterID(), tempItem2, 0);
  7628. player->item_list.DestroyItem(tempItem2->details.index);
  7629. }
  7630. }
  7631. // 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
  7632. player->RemoveCoins(ItemInfo->price_coins * quantity);
  7633. item->SetMaxSellValue(sell_price);
  7634. if (quantity > 1)
  7635. 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());
  7636. else
  7637. 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());
  7638. bool itemDeleted = false;
  7639. AddItem(item, &itemDeleted);
  7640. if (!itemDeleted) {
  7641. CheckPlayerQuestsItemUpdate(item);
  7642. if (item && total_available < 0xFF) {
  7643. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  7644. SendBuyMerchantList();
  7645. }
  7646. SendSellMerchantList();
  7647. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  7648. PlayLotto(total_buy_price, item->details.item_id);
  7649. }
  7650. }
  7651. else {
  7652. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  7653. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  7654. PlaySound("buy_failed");
  7655. }
  7656. }
  7657. else {
  7658. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  7659. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  7660. PlaySound("buy_failed");
  7661. }
  7662. }
  7663. }
  7664. }
  7665. }
  7666. }
  7667. void Client::RepairItem(int32 item_id) {
  7668. Spawn* spawn = GetMerchantTransaction();
  7669. if (spawn) {
  7670. Item* item = player->item_list.GetItemFromID(item_id);
  7671. if (!item)
  7672. item = player->GetEquipmentList()->GetItemFromItemID(item_id);
  7673. if (item) {
  7674. if (item->CheckFlag2(NO_REPAIR)) {
  7675. Message(CHANNEL_MERCHANT, "The mender was unable to repair your items.");
  7676. PlaySound("buy_failed");
  7677. }
  7678. else {
  7679. int32 repair_cost = item->CalculateRepairCost();
  7680. if (player->RemoveCoins((int32)repair_cost)) {
  7681. item->generic_info.condition = 100;
  7682. item->save_needed = true;
  7683. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  7684. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  7685. QueuePacket(item->serialize(version, false, player));
  7686. Message(CHANNEL_MERCHANT, "You give %s %s to repair your %s.", spawn->GetName(), GetCoinMessage(repair_cost).c_str(), item->CreateItemLink(GetVersion()).c_str());
  7687. PlaySound("coin_cha_ching");
  7688. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  7689. SendRepairList();
  7690. }
  7691. else {
  7692. string popup_text = "You do not have enough coin to repair ";
  7693. string popup_item = item->CreateItemLink(GetVersion()).c_str();
  7694. popup_text.append(popup_item);
  7695. SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  7696. Message(CHANNEL_MERCHANT, "You do not have enough coin to repair %s.", item->CreateItemLink(GetVersion()).c_str());
  7697. PlaySound("buy_failed");
  7698. }
  7699. }
  7700. }
  7701. }
  7702. }
  7703. void Client::RepairAllItems() {
  7704. Spawn* spawn = GetMerchantTransaction();
  7705. if (spawn) {
  7706. vector<Item*>* repairable_items = GetRepairableItems();
  7707. if (repairable_items && repairable_items->size() > 0) {
  7708. vector<Item*>::iterator itr;
  7709. int64 total_cost = 0;
  7710. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++)
  7711. total_cost += (*itr)->CalculateRepairCost();
  7712. if (player->RemoveCoins((int32)total_cost)) {
  7713. Message(CHANNEL_MERCHANT, "You give %s to repair all of your items.", GetCoinMessage((int32)total_cost).c_str());
  7714. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++) {
  7715. Item* item = *itr;
  7716. if (item) {
  7717. item->generic_info.condition = 100;
  7718. item->save_needed = true;
  7719. QueuePacket(item->serialize(version, false, player));
  7720. Message(CHANNEL_COLOR_YELLOW, "Repaired: %s.", item->CreateItemLink(GetVersion()).c_str());
  7721. }
  7722. }
  7723. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  7724. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  7725. PlaySound("coin_cha_ching");
  7726. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  7727. SendRepairList();
  7728. }
  7729. else {
  7730. string popup_text = "You do not have enough coin to repair all of your items. ";
  7731. SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  7732. SimpleMessage(CHANNEL_MERCHANT, "You do not have enough coin to repair all of your items.");
  7733. PlaySound("buy_failed");
  7734. }
  7735. }
  7736. safe_delete(repairable_items);
  7737. }
  7738. }
  7739. void Client::SendAchievementsList()
  7740. {
  7741. /*map<int32, Achievement *> *achievements = player->GetAchievementList()->GetAchievements();
  7742. map<int32, Achievement *>::iterator itr;
  7743. Achievement *achievement;
  7744. vector<AchievementRequirements *> *requirements = 0;
  7745. vector<AchievementRequirements *>::iterator itr2;
  7746. AchievementRequirements *requirement;
  7747. vector<AchievementRewards *> *rewards = 0;
  7748. vector<AchievementRewards *>::iterator itr3;
  7749. AchievementRewards *reward;
  7750. PacketStruct *packet;
  7751. int16 i = 0;
  7752. int16 j = 0;
  7753. int16 k = 0;
  7754. if (!(packet = configReader.getStruct("WS_CharacterAchievements", version))) {
  7755. return;
  7756. }
  7757. packet->setArrayLengthByName("num_achievements" , achievements->size());
  7758. for (itr = achievements->begin(); itr != achievements->end(); itr++) {
  7759. achievement = itr->second;
  7760. packet->setArrayDataByName("achievement_id", achievement->GetID(), i);
  7761. packet->setArrayDataByName("title", achievement->GetTitle(), i);
  7762. packet->setArrayDataByName("uncompleted_text", achievement->GetUncompletedText(), i);
  7763. packet->setArrayDataByName("completed_text", achievement->GetCompletedText(), i);
  7764. packet->setArrayDataByName("category", achievement->GetCategory(), i);
  7765. packet->setArrayDataByName("expansion", achievement->GetExpansion(), i);
  7766. packet->setArrayDataByName("icon", achievement->GetIcon(), i);
  7767. packet->setArrayDataByName("point_value", achievement->GetPointValue(), i);
  7768. packet->setArrayDataByName("qty_req", achievement->GetQtyReq(), i);
  7769. packet->setArrayDataByName("hide_achievement", achievement->GetHide(), i);
  7770. packet->setArrayDataByName("unknown3", achievement->GetUnknown3a(), i);
  7771. packet->setArrayDataByName("unknown3", achievement->GetUnknown3b(), i);
  7772. requirements = achievement->GetRequirements();
  7773. rewards = achievement->GetRewards();
  7774. j = 0;
  7775. k = 0;
  7776. packet->setSubArrayLengthByName("num_items", requirements->size(), i, j);
  7777. for (itr2 = requirements->begin(); itr2 != requirements->end(); itr2++) {
  7778. requirement = *itr2;
  7779. packet->setSubArrayDataByName("item_name", requirement->name.c_str(), i, j);
  7780. packet->setSubArrayDataByName("item_qty_req", requirement->qty_req, i, j);
  7781. j++;
  7782. }
  7783. packet->setSubArrayLengthByName("num_rewards", achievement->GetRewards()->size(), i, k);
  7784. for (itr3 = rewards->begin(); itr3 != rewards->end(); itr3++) {
  7785. reward = *itr3;
  7786. packet->setSubArrayDataByName("reward_item", reward->reward.c_str(), i, k);
  7787. k++;
  7788. }
  7789. i++;
  7790. }
  7791. //packet->PrintPacket();
  7792. EQ2Packet* data = packet->serialize();
  7793. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  7794. safe_delete(packet);
  7795. safe_delete(data);
  7796. //DumpPacket(app);
  7797. QueuePacket(app);*/
  7798. QueuePacket(master_achievement_list.GetAchievementPacket()->Copy());
  7799. SendAchievementUpdate(true);
  7800. }
  7801. void Client::SendAchievementUpdate(bool first_login) {
  7802. map<int32, AchievementUpdate*>* updates = player->GetAchievementUpdateList()->GetAchievementUpdates();
  7803. map<int32, AchievementUpdate*>::iterator itr;
  7804. AchievementUpdate* update;
  7805. vector<AchievementUpdateItems*>* update_items = 0;
  7806. vector<AchievementUpdateItems*>::iterator itr2;
  7807. AchievementUpdateItems* update_item;
  7808. int16 i = 0;
  7809. int16 j = 0;
  7810. PacketStruct* packet;
  7811. if (!(packet = configReader.getStruct("WS_AchievementUpdate", version))) {
  7812. return;
  7813. }
  7814. packet->setDataByName("unknown1", first_login ? 1 : 0);
  7815. packet->setArrayLengthByName("num_achievements", updates->size());
  7816. for (itr = updates->begin(); itr != updates->end(); itr++) {
  7817. update = itr->second;
  7818. packet->setArrayDataByName("achievement_id", update->GetID(), i);
  7819. packet->setArrayDataByName("completed_date", update->GetCompletedDate(), i);
  7820. update_items = update->GetUpdateItems();
  7821. j = 0;
  7822. packet->setSubArrayLengthByName("num_items", update_items->size(), i);
  7823. for (itr2 = update_items->begin(); itr2 != update_items->end(); itr2++) {
  7824. update_item = *itr2;
  7825. packet->setSubArrayDataByName("item_update", update_item->item_update, i, j);
  7826. j++;
  7827. }
  7828. i++;
  7829. }
  7830. //packet->PrintPacket();
  7831. EQ2Packet* data = packet->serialize();
  7832. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  7833. safe_delete(packet);
  7834. safe_delete(data);
  7835. //DumpPacket(app);
  7836. QueuePacket(app);
  7837. }
  7838. void Client::SendBuyMerchantList(bool sell) {
  7839. Spawn* spawn = GetMerchantTransaction();
  7840. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  7841. vector<MerchantItemInfo>* items = world.GetMerchantItemList(spawn->GetMerchantID(), spawn->GetMerchantType(), player);
  7842. if (items) {
  7843. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7844. if (packet) {
  7845. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  7846. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7847. packet->setArrayLengthByName("num_items", items->size());
  7848. vector<MerchantItemInfo>::iterator itr;
  7849. sint8 item_difficulty = 0;
  7850. int32 sell_price = 0;
  7851. int i = 0;
  7852. int tmp_level = 0;
  7853. for (itr = items->begin(); itr != items->end(); itr++, i++) {
  7854. MerchantItemInfo ItemInfo = *itr;
  7855. Item* item = master_item_list.GetItem(ItemInfo.item_id);
  7856. if (!item)
  7857. continue;
  7858. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  7859. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7860. packet->setArrayDataByName("stack_size", item->stack_count, i);
  7861. packet->setArrayDataByName("icon", item->GetIcon(GetVersion()), i);
  7862. if (item->generic_info.adventure_default_level > 0)
  7863. tmp_level = item->generic_info.adventure_default_level;
  7864. else
  7865. tmp_level = item->generic_info.tradeskill_default_level;
  7866. packet->setArrayDataByName("level", tmp_level, i);
  7867. if (rule_manager.GetZoneRule(GetCurrentZoneID(), R_World, DisplayItemTiers)->GetBool()) {
  7868. packet->setArrayDataByName("tier", item->details.tier, i);
  7869. }
  7870. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  7871. item_difficulty = player->GetArrowColor(tmp_level);
  7872. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7873. item_difficulty = ARROW_COLOR_WHITE;
  7874. sint64 overrideValue = 0;
  7875. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "item_difficulty", item, player, nullptr, &overrideValue))
  7876. item_difficulty = (sint8)overrideValue;
  7877. item_difficulty -= 6;
  7878. if (item_difficulty < 0)
  7879. item_difficulty *= -1;
  7880. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7881. packet->setArrayDataByName("quantity", ItemInfo.quantity, i);
  7882. packet->setArrayDataByName("unknown5", 255, i);
  7883. packet->setArrayDataByName("stack_size2", item->stack_count, i);
  7884. sint64 dispFlags = 0;
  7885. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "buy_display_flags", item, player, nullptr, &dispFlags))
  7886. packet->setArrayDataByName("display_flags", (int8)dispFlags, i);
  7887. std::string overrideValueStr;
  7888. // 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)
  7889. if (GetVersion() >= 546 && item->GetItemScript() && lua_interface && lua_interface->RunItemScriptWithReturnString(item->GetItemScript(), "item_description", item, player, &overrideValueStr))
  7890. packet->setArrayDataByName("description", overrideValueStr.c_str(), i);
  7891. // If no price set in the merchant_inventory table then use the old method
  7892. if (ItemInfo.price_item_id == 0 && ItemInfo.price_item2_id == 0 && ItemInfo.price_coins == 0 && ItemInfo.price_status == 0 && ItemInfo.price_stationcash == 0) {
  7893. sell_price = (int32)(item->sell_price * multiplier);
  7894. packet->setArrayDataByName("price", sell_price, i);
  7895. }
  7896. else {
  7897. int8 count = 0;
  7898. if (ItemInfo.price_item_id != 0 && ItemInfo.price_item_qty != 0)
  7899. count++;
  7900. if (ItemInfo.price_item2_id != 0 && ItemInfo.price_item2_qty != 0)
  7901. count++;
  7902. if (count != 0) {
  7903. packet->setSubArrayLengthByName("num_tokens", count, i);
  7904. int8 index = 0;
  7905. Item* token = 0;
  7906. if (ItemInfo.price_item_id != 0) {
  7907. token = master_item_list.GetItem(ItemInfo.price_item_id);
  7908. if (item) {
  7909. packet->setSubArrayDataByName("token_icon", token->GetIcon(GetVersion()), i, index);
  7910. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item_qty, i, index);
  7911. packet->setSubArrayDataByName("token_id", ItemInfo.price_item_id, i, index);
  7912. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  7913. }
  7914. token = 0;
  7915. index++;
  7916. }
  7917. if (ItemInfo.price_item2_id != 0) {
  7918. token = master_item_list.GetItem(ItemInfo.price_item2_id);
  7919. if (item) {
  7920. packet->setSubArrayDataByName("token_icon", token->GetIcon(GetVersion()), i, index);
  7921. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item2_qty, i, index);
  7922. packet->setSubArrayDataByName("token_id", ItemInfo.price_item2_id, i, index);
  7923. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  7924. }
  7925. }
  7926. }
  7927. packet->setArrayDataByName("price", ItemInfo.price_coins, i);
  7928. packet->setArrayDataByName("status2", ItemInfo.price_status, i);
  7929. packet->setArrayDataByName("station_cash", ItemInfo.price_stationcash, i);
  7930. }
  7931. }
  7932. if (GetVersion() < 561) {
  7933. //buy is 0 so dont need to set it
  7934. if (sell)
  7935. packet->setDataByName("type", 1);
  7936. }
  7937. else if (GetVersion() == 561) {
  7938. packet->setDataByName("type", 2);
  7939. }
  7940. else {
  7941. if (sell)
  7942. packet->setDataByName("type", 130);
  7943. else
  7944. packet->setDataByName("type", 2);
  7945. }
  7946. EQ2Packet* outapp = packet->serialize();
  7947. QueuePacket(outapp);
  7948. safe_delete(packet);
  7949. }
  7950. safe_delete(items);
  7951. }
  7952. else {
  7953. // Need to send an empty packet in the event there is no item list, otherwise the
  7954. // last item list sent to the player will show for this merchant
  7955. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7956. if (packet) {
  7957. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7958. if (GetVersion() <= 561) {
  7959. //buy is 0 so dont need to set it
  7960. if (sell)
  7961. packet->setDataByName("type", 1);
  7962. }
  7963. else {
  7964. if (sell)
  7965. packet->setDataByName("type", 130);
  7966. else
  7967. packet->setDataByName("type", 2);
  7968. }
  7969. EQ2Packet* outapp = packet->serialize();
  7970. QueuePacket(outapp);
  7971. safe_delete(packet);
  7972. }
  7973. }
  7974. }
  7975. }
  7976. void Client::SendSellMerchantList(bool sell) {
  7977. Spawn* spawn = GetMerchantTransaction();
  7978. if (!spawn || (spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY) || (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO))
  7979. return;
  7980. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  7981. map<int32, Item*>* items = player->GetItemList();
  7982. if (items) {
  7983. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7984. if (packet) {
  7985. vector<Item*> sellable_items;
  7986. map<int32, Item*>::iterator test_itr;
  7987. for (test_itr = items->begin(); test_itr != items->end(); test_itr++) {
  7988. bool isbagwithitems = false;
  7989. 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))
  7990. isbagwithitems = true;
  7991. 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))
  7992. sellable_items.push_back(test_itr->second);
  7993. }
  7994. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7995. packet->setArrayLengthByName("num_items", sellable_items.size());
  7996. vector<Item*>::iterator itr;
  7997. Item* item = 0;
  7998. sint8 item_difficulty = 0;
  7999. float multiplier = CalculateSellMultiplier(spawn->GetMerchantID());
  8000. int32 sell_price = 0;
  8001. Item* master_item = 0;
  8002. int i = 0;
  8003. int tmp_level = 0;
  8004. for (itr = sellable_items.begin(); itr != sellable_items.end(); itr++, i++) {
  8005. item = *itr;
  8006. master_item = master_item_list.GetItem(item->details.item_id);
  8007. if (master_item)
  8008. sell_price = (int32)(master_item->sell_price * multiplier);
  8009. else
  8010. sell_price = 0;
  8011. if (sell_price > item->sell_price)
  8012. sell_price = item->sell_price;
  8013. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  8014. string thename = item->name;
  8015. packet->setArrayDataByName("price", sell_price, i);
  8016. packet->setArrayDataByName("status", 0, i);//additive to status 2 maybe for server bonus etc
  8017. int8 dispFlags = 0;
  8018. // only city merchants allow selling for status
  8019. if (item->sell_status > 0 && (spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT))
  8020. {
  8021. packet->setArrayDataByName("status2", item->sell_status, i); //this one is the main status
  8022. int32 guildMaxLevel = 5 + item->details.recommended_level; // client hard codes +5 to the level
  8023. if (GetPlayer()->GetGuild() && GetPlayer()->GetGuild()->GetLevel() >= guildMaxLevel) {
  8024. dispFlags += DISPLAY_FLAG_NO_GUILD_STATUS;
  8025. }
  8026. }
  8027. if (item->no_buy_back || (item->sell_status > 0 && (spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))
  8028. {
  8029. if (GetVersion() < 1188)
  8030. 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
  8031. else
  8032. dispFlags += DISPLAY_FLAG_NO_BUYBACK;
  8033. }
  8034. if (item->no_sale)
  8035. dispFlags += DISPLAY_FLAG_NOT_FOR_SALE;
  8036. packet->setArrayDataByName("display_flags", dispFlags, i);
  8037. packet->setArrayDataByName("item_id", item->details.item_id, i);
  8038. packet->setArrayDataByName("unique_item_id", item->details.unique_id, i);
  8039. packet->setArrayDataByName("stack_size", item->details.count, i);
  8040. packet->setArrayDataByName("icon", item->GetIcon(GetVersion()), i);
  8041. if (item->generic_info.adventure_default_level > 0)
  8042. tmp_level = item->generic_info.adventure_default_level;
  8043. else
  8044. tmp_level = item->generic_info.tradeskill_default_level;
  8045. packet->setArrayDataByName("level", item->details.recommended_level, i);
  8046. if (rule_manager.GetZoneRule(GetCurrentZoneID(), R_World, DisplayItemTiers)->GetBool()) {
  8047. packet->setArrayDataByName("tier", item->details.tier, i);
  8048. }
  8049. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  8050. item_difficulty = player->GetArrowColor(tmp_level);
  8051. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  8052. item_difficulty = ARROW_COLOR_WHITE;
  8053. sint64 overrideValue = 0;
  8054. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "item_difficulty", item, player, nullptr, &overrideValue))
  8055. item_difficulty = (sint8)overrideValue;
  8056. item_difficulty -= 6;
  8057. if (item_difficulty < 0)
  8058. item_difficulty *= -1;
  8059. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  8060. if (item->details.count == 1)
  8061. packet->setArrayDataByName("quantity", 0xFFFF, i);
  8062. else
  8063. packet->setArrayDataByName("quantity", item->details.count, i);
  8064. packet->setArrayDataByName("stack_size2", item->details.count, i);
  8065. if (GetVersion() <= 1096)
  8066. packet->setArrayDataByName("description", item->description.c_str(), i);
  8067. }
  8068. if (GetVersion() < 561) {
  8069. packet->setDataByName("type", 1);
  8070. }
  8071. else if (GetVersion() == 561) {
  8072. packet->setDataByName("type", 1);
  8073. }
  8074. else {
  8075. if (sell)
  8076. packet->setDataByName("type", 129);
  8077. else
  8078. packet->setDataByName("type", 1);
  8079. }
  8080. packet->setDataByName("unknown8a", 16256, 6);
  8081. packet->setDataByName("unknown8a", 16256, 10);
  8082. //packet->PrintPacket();
  8083. EQ2Packet* outapp = packet->serialize();
  8084. //DumpPacket(outapp);
  8085. QueuePacket(outapp);
  8086. safe_delete(packet);
  8087. }
  8088. safe_delete(items);
  8089. }
  8090. }
  8091. }
  8092. void Client::SendBuyBackList(bool sell) {
  8093. if (GetVersion() <= 561) //this wasn't added until LU37 on July 31st 2007, well after the DoF client
  8094. return;
  8095. Spawn* spawn = GetMerchantTransaction();
  8096. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  8097. deque<BuyBackItem*>::iterator itr;
  8098. int i = 0;
  8099. Item* master_item = 0;
  8100. BuyBackItem* buyback = 0;
  8101. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  8102. if (packet) {
  8103. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  8104. packet->setArrayLengthByName("num_items", buy_back_items.size());
  8105. sint8 item_difficulty = 0;
  8106. MBuyBack.readlock(__FUNCTION__, __LINE__);
  8107. int tmp_level = 0;
  8108. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++, i++) {
  8109. buyback = *itr;
  8110. master_item = master_item_list.GetItem(buyback->item_id);
  8111. if (master_item) {
  8112. packet->setArrayDataByName("item_name", master_item->name.c_str(), i);
  8113. packet->setArrayDataByName("price", buyback->price, i);
  8114. packet->setArrayDataByName("item_id", master_item->details.item_id, i);
  8115. packet->setArrayDataByName("unique_item_id", buyback->unique_id, i);
  8116. packet->setArrayDataByName("stack_size", buyback->quantity, i);
  8117. packet->setArrayDataByName("icon", master_item->GetIcon(GetVersion()), i);
  8118. if (master_item->generic_info.adventure_default_level > 0)
  8119. tmp_level = master_item->generic_info.adventure_default_level;
  8120. else
  8121. tmp_level = master_item->generic_info.tradeskill_default_level;
  8122. packet->setArrayDataByName("level", tmp_level, i);
  8123. if (rule_manager.GetZoneRule(GetCurrentZoneID(), R_World, DisplayItemTiers)->GetBool()) {
  8124. packet->setArrayDataByName("tier", master_item->details.tier, i);
  8125. }
  8126. packet->setArrayDataByName("item_id2", master_item->details.item_id, i);
  8127. item_difficulty = player->GetArrowColor(tmp_level);
  8128. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  8129. item_difficulty = ARROW_COLOR_WHITE;
  8130. sint64 overrideValue = 0;
  8131. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "item_difficulty", master_item, player, nullptr, &overrideValue))
  8132. item_difficulty = (sint8)overrideValue;
  8133. item_difficulty -= 6;
  8134. if (item_difficulty < 0)
  8135. item_difficulty *= -1;
  8136. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  8137. sint64 dispFlags = 0;
  8138. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "buyback_display_flags", master_item, player, nullptr, &dispFlags))
  8139. packet->setArrayDataByName("display_flags", (int8)dispFlags, i);
  8140. if (buyback->quantity == 1)
  8141. packet->setArrayDataByName("quantity", 0xFFFF, i);
  8142. else
  8143. packet->setArrayDataByName("quantity", buyback->quantity, i);
  8144. packet->setArrayDataByName("stack_size2", buyback->quantity, i);
  8145. if (GetVersion() <= 1096)
  8146. packet->setArrayDataByName("description", master_item->description.c_str(), i);
  8147. }
  8148. }
  8149. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  8150. if (sell)
  8151. packet->setDataByName("type", 640);
  8152. else
  8153. packet->setDataByName("type", 512);
  8154. EQ2Packet* outapp = packet->serialize();
  8155. // DumpPacket(outapp);
  8156. QueuePacket(outapp);
  8157. safe_delete(packet);
  8158. }
  8159. }
  8160. }
  8161. void Client::SendRepairList() {
  8162. Spawn* spawn = GetMerchantTransaction();
  8163. if (spawn) {
  8164. vector<Item*>* repairable_items = GetRepairableItems();
  8165. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  8166. if (packet) {
  8167. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  8168. packet->setArrayLengthByName("num_items", repairable_items->size());
  8169. Item* item = 0;
  8170. sint8 item_difficulty = 0;
  8171. int32 i = 0;
  8172. vector<Item*>::iterator itr;
  8173. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++, i++) {
  8174. item = *itr;
  8175. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  8176. packet->setArrayDataByName("price", item->CalculateRepairCost(), i);
  8177. packet->setArrayDataByName("item_id", item->details.item_id, i);
  8178. packet->setArrayDataByName("stack_size", item->details.count, i);
  8179. packet->setArrayDataByName("icon", item->GetIcon(GetVersion()), i);
  8180. /*if (item->generic_info.adventure_default_level > 0)
  8181. tmp_level = item->generic_info.adventure_default_level;
  8182. else
  8183. tmp_level = item->generic_info.tradeskill_default_level;
  8184. packet->setArrayDataByName("level", tmp_level, i);*/
  8185. packet->setArrayDataByName("level", item->generic_info.adventure_default_level, i);
  8186. if (rule_manager.GetZoneRule(GetCurrentZoneID(), R_World, DisplayItemTiers)->GetBool()) {
  8187. packet->setArrayDataByName("tier", item->details.tier, i);
  8188. }
  8189. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  8190. item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  8191. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  8192. item_difficulty = ARROW_COLOR_WHITE;
  8193. item_difficulty -= 6;
  8194. if (item_difficulty < 0)
  8195. item_difficulty *= -1;
  8196. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  8197. if (item->details.count == 1)
  8198. packet->setArrayDataByName("quantity", 0xFFFF, i);
  8199. else
  8200. packet->setArrayDataByName("quantity", item->details.count, i);
  8201. packet->setArrayDataByName("stack_size2", item->details.count, i);
  8202. if (GetVersion() <= 1096)
  8203. packet->setArrayDataByName("description", item->description.c_str(), i);
  8204. }
  8205. if (GetVersion() <= 561) {
  8206. packet->setDataByName("type", 112);
  8207. }
  8208. else {
  8209. packet->setDataByName("type", 96);
  8210. }
  8211. EQ2Packet* outapp = packet->serialize();
  8212. //DumpPacket(outapp);
  8213. QueuePacket(outapp);
  8214. /*if (GetVersion() <= 561) {
  8215. packet->setDataByName("type", 16);
  8216. EQ2Packet* outapp2 = packet->serialize();
  8217. QueuePacket(outapp2);
  8218. }*/
  8219. safe_delete(packet);
  8220. }
  8221. safe_delete(repairable_items);
  8222. }
  8223. }
  8224. void Client::ShowLottoWindow() {
  8225. if (GetVersion() <= 373) {
  8226. SimpleMessage(CHANNEL_COLOR_RED, "This client does not support the gambler UI, only Desert of Flames or later client.");
  8227. return;
  8228. }
  8229. Spawn* spawn = GetMerchantTransaction();
  8230. if (spawn) {
  8231. int32 item_id = rule_manager.GetZoneRule(GetCurrentZoneID(), R_World, GamblingTokenItemID)->GetInt32();
  8232. if (!item_id)
  8233. {
  8234. LogWrite(WORLD__ERROR, 0, "World", "No GamblingTokenItemID rule set!");
  8235. SimpleMessage(CHANNEL_COLOR_RED, "The server admin has not setup a lotto item ticket.");
  8236. return;
  8237. }
  8238. else if (item_id == 0)
  8239. {
  8240. LogWrite(WORLD__ERROR, 0, "World", "Error! Invalid GamblingTokenItemID value!");
  8241. return;
  8242. }
  8243. Item* item = master_item_list.GetItem(item_id);
  8244. if (!item) {
  8245. LogWrite(WORLD__ERROR, 0, "World", "The 'GamblingTokenItemID' rule value %u is not a valid item id.", item_id);
  8246. return;
  8247. }
  8248. LogWrite(WORLD__DEBUG, 0, "World", "GamblingTokenItemID = '%s' (%u)", item->name.c_str(), item_id);
  8249. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  8250. if (packet) {
  8251. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  8252. packet->setArrayLengthByName("num_items", 1);
  8253. packet->setArrayDataByName("item_name", item->name.c_str());
  8254. packet->setArrayDataByName("price", item->sell_price);
  8255. packet->setArrayDataByName("item_id", item->details.item_id);
  8256. packet->setArrayDataByName("stack_size", item->details.count);
  8257. packet->setArrayDataByName("icon", item->GetIcon(GetVersion()));
  8258. packet->setArrayDataByName("level", item->generic_info.adventure_default_level);
  8259. if (rule_manager.GetZoneRule(GetCurrentZoneID(), R_World, DisplayItemTiers)->GetBool()) {
  8260. packet->setArrayDataByName("tier", item->details.tier);
  8261. }
  8262. packet->setArrayDataByName("item_id2", item->details.item_id);
  8263. int8 item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  8264. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  8265. item_difficulty = ARROW_COLOR_WHITE;
  8266. item_difficulty -= 6;
  8267. if (item_difficulty < 0)
  8268. item_difficulty *= -1;
  8269. packet->setArrayDataByName("item_difficulty", item_difficulty);
  8270. //if(item->details.count == 1)
  8271. packet->setArrayDataByName("quantity", 0xFFFF);
  8272. //else
  8273. // packet->setArrayDataByName("quantity", item->details.count);
  8274. packet->setArrayDataByName("stack_size2", item->details.count);
  8275. packet->setArrayDataByName("description", item->description.c_str());
  8276. if (GetVersion() <= 546) {
  8277. packet->setDataByName("type", 128);
  8278. }
  8279. else {
  8280. packet->setDataByName("type", 0x00000102);
  8281. }
  8282. QueuePacket(packet->serialize());
  8283. safe_delete(packet);
  8284. }
  8285. }
  8286. }
  8287. void Client::PlayLotto(int32 price, int32 ticket_item_id) {
  8288. PacketStruct* packet = configReader.getStruct("WS_Lottery", GetVersion());
  8289. if (packet) {
  8290. world.AddLottoPlayer(GetCharacterID(), Timer::GetCurrentTime2() + 4500);
  8291. int32 rolls[6] = { 0 };
  8292. int32 lottery_digits[6] = { 0 };
  8293. int8 num_matches = 0;
  8294. int64 jackpot = 0;
  8295. Item* item = GetPlayer()->item_list.GetItemFromID(ticket_item_id);
  8296. if (!item) {
  8297. return;
  8298. }
  8299. database.DeleteItem(GetCharacterID(), item, 0);
  8300. GetPlayer()->item_list.RemoveItem(item, true);
  8301. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  8302. Variable* winning_numbers = variables.FindVariable("gambling_winning_numbers");
  8303. if (!winning_numbers) {
  8304. winning_numbers = new Variable("gambling_winning_numbers", "231205182236", "Current Gigglegibber Gambling Game winning numbers");
  8305. variables.AddVariable(winning_numbers);
  8306. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  8307. }
  8308. if (strlen(winning_numbers->GetValue()) != 12) {
  8309. winning_numbers->SetValue("231205182236");
  8310. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  8311. }
  8312. try {
  8313. for (int32 i = 0; i < 12; i += 2) {
  8314. char num[4];
  8315. strncpy(num, winning_numbers->GetValue() + i, 2);
  8316. lottery_digits[i / 2] = atoi(num);
  8317. }
  8318. }
  8319. catch (...) {
  8320. LogWrite(WORLD__ERROR, 0, "World", "Error parsing 'gambling_winning_numbers' variable");
  8321. return;
  8322. }
  8323. Variable* jackpot_var = variables.FindVariable("gambling_current_jackpot");
  8324. if (!jackpot_var) {
  8325. jackpot_var = new Variable("gambling_current_jackpot", "10000", "Current Gigglegibber Gambling Game Jackpot");
  8326. variables.AddVariable(jackpot_var);
  8327. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  8328. }
  8329. try {
  8330. jackpot = atoul(jackpot_var->GetValue());
  8331. if (jackpot < 10000)
  8332. jackpot = 10000;
  8333. }
  8334. catch (...) {
  8335. jackpot = 10000;
  8336. }
  8337. char new_jackpot[128] = { 0 };
  8338. sprintf(new_jackpot, "%llu", jackpot + price);
  8339. jackpot_var->SetValue(new_jackpot);
  8340. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  8341. world.PickRandomLottoDigits(rolls);
  8342. packet->setDataByName("roll_digit1", rolls[0]);
  8343. packet->setDataByName("roll_digit2", rolls[1]);
  8344. packet->setDataByName("roll_digit3", rolls[2]);
  8345. packet->setDataByName("roll_digit4", rolls[3]);
  8346. packet->setDataByName("roll_digit5", rolls[4]);
  8347. packet->setDataByName("roll_digit6", rolls[5]);
  8348. packet->setDataByName("lottery_digit1", lottery_digits[0]);
  8349. packet->setDataByName("lottery_digit2", lottery_digits[1]);
  8350. packet->setDataByName("lottery_digit3", lottery_digits[2]);
  8351. packet->setDataByName("lottery_digit4", lottery_digits[3]);
  8352. packet->setDataByName("lottery_digit5", lottery_digits[4]);
  8353. packet->setDataByName("lottery_digit6", lottery_digits[5]);
  8354. QueuePacket(packet->serialize());
  8355. safe_delete(packet);
  8356. for (int32 i = 0; i < 6; i++) {
  8357. for (int32 j = 0; j < 6; j++) {
  8358. if (rolls[i] == lottery_digits[j]) {
  8359. num_matches++;
  8360. break;
  8361. }
  8362. }
  8363. }
  8364. char new_jackpot_str[16];
  8365. memset(new_jackpot_str, 0, sizeof(new_jackpot_str));
  8366. world.SetLottoPlayerNumMatches(GetCharacterID(), num_matches);
  8367. if (num_matches == 6) {
  8368. world.PickRandomLottoDigits(lottery_digits);
  8369. for (int32 i = 0; i < 12; i += 2)
  8370. sprintf(new_jackpot_str + i, "%02d", lottery_digits[i / 2]);
  8371. winning_numbers->SetValue(new_jackpot_str);
  8372. jackpot_var->SetValue("10000");
  8373. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  8374. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  8375. }
  8376. }
  8377. }
  8378. void Client::SendGuildCreateWindow() {
  8379. if (GetVersion() <= 561) {
  8380. SimpleMessage(0, "Not implemented on this client...yet?");
  8381. }
  8382. else {
  8383. Spawn* spawn = GetPlayer()->GetTarget();
  8384. if (spawn) {
  8385. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  8386. if (packet) {
  8387. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  8388. packet->setArrayLengthByName("num_items", 0);
  8389. packet->setDataByName("type", 0x00008000);
  8390. QueuePacket(packet->serialize());
  8391. safe_delete(packet);
  8392. }
  8393. }
  8394. }
  8395. }
  8396. void Client::AddBuyBack(int32 unique_id, int32 item_id, int16 quantity, int32 price, bool save_needed) {
  8397. BuyBackItem* item = new BuyBackItem;
  8398. item->item_id = item_id;
  8399. item->unique_id = unique_id;
  8400. item->price = price;
  8401. item->quantity = quantity;
  8402. item->save_needed = save_needed;
  8403. MBuyBack.writelock(__FUNCTION__, __LINE__);
  8404. buy_back_items.push_back(item);
  8405. if (buy_back_items.size() > 10) {
  8406. safe_delete(buy_back_items.front());
  8407. buy_back_items.pop_front();
  8408. }
  8409. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  8410. }
  8411. deque<BuyBackItem*>* Client::GetBuyBacks() {
  8412. return &buy_back_items;
  8413. }
  8414. vector<Item*>* Client::GetRepairableItems() {
  8415. vector<Item*>* repairable_items = new vector<Item*>;
  8416. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  8417. map<int32, Item*>* items = player->GetItemList();
  8418. if (equipped_items && equipped_items->size() > 0) {
  8419. for (int32 i = 0; i < equipped_items->size(); i++) {
  8420. Item* item = equipped_items->at(i);
  8421. if (item && !item->CheckFlag2(NO_REPAIR) && item->generic_info.condition < 100)
  8422. repairable_items->push_back(item);
  8423. }
  8424. }
  8425. if (items && items->size() > 0) {
  8426. map<int32, Item*>::iterator itr;
  8427. for (itr = items->begin(); itr != items->end(); itr++) {
  8428. Item* item = itr->second;
  8429. if (item && !item->CheckFlag2(NO_REPAIR) && item->generic_info.condition < 100)
  8430. repairable_items->push_back(item);
  8431. }
  8432. }
  8433. safe_delete(equipped_items);
  8434. safe_delete(items);
  8435. return repairable_items;
  8436. }
  8437. vector<Item*>* Client::GetItemsByEffectType(ItemEffectType type, ItemEffectType type2) {
  8438. if (type == NO_EFFECT_TYPE)
  8439. return nullptr;
  8440. vector<Item*>* return_items = new vector<Item*>;
  8441. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  8442. map<int32, Item*>* items = player->GetItemList();
  8443. if (equipped_items && equipped_items->size() > 0) {
  8444. for (int32 i = 0; i < equipped_items->size(); i++) {
  8445. Item* item = equipped_items->at(i);
  8446. if (item && (item->effect_type == type || (type2 != NO_EFFECT_TYPE && item->effect_type == type2)))
  8447. return_items->push_back(item);
  8448. }
  8449. }
  8450. if (items && items->size() > 0) {
  8451. map<int32, Item*>::iterator itr;
  8452. for (itr = items->begin(); itr != items->end(); itr++) {
  8453. Item* item = itr->second;
  8454. if (item && (item->effect_type == type || (type2 != NO_EFFECT_TYPE && item->effect_type == type2)))
  8455. return_items->push_back(item);
  8456. }
  8457. }
  8458. safe_delete(equipped_items);
  8459. safe_delete(items);
  8460. return return_items;
  8461. }
  8462. void Client::SendMailList() {
  8463. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  8464. if (kiosk_id > 0) {
  8465. PacketStruct* p = configReader.getStruct("WS_GetMailHeader", GetVersion());
  8466. if (p) {
  8467. MutexMap<int32, Mail*>* mail_list = player->GetMail();
  8468. MutexMap<int32, Mail*>::iterator itr = mail_list->begin();
  8469. int32 i = 0;
  8470. p->setDataByName("kiosk_id", kiosk_id);
  8471. p->setArrayLengthByName("num_messages", (int16)mail_list->size());
  8472. while (itr.Next()) {
  8473. Mail* mail = itr->second;
  8474. p->setArrayDataByName("mail_id", mail->mail_id, i);
  8475. p->setArrayDataByName("player_to_id", mail->player_to_id, i);
  8476. p->setArrayDataByName("player_from", mail->player_from.c_str(), i);
  8477. p->setArrayDataByName("subject", mail->subject.c_str(), i);
  8478. p->setArrayDataByName("already_read", mail->already_read, i);
  8479. if (mail->expire_time)
  8480. p->setArrayDataByName("mail_deletion", mail->expire_time - mail->time_sent, i);
  8481. else
  8482. p->setArrayDataByName("mail_deletion", 0, i);
  8483. p->setArrayDataByName("mail_type", mail->mail_type, i);
  8484. p->setArrayDataByName("mail_expire", 0xFFFFFFFF, i);
  8485. p->setArrayDataByName("unknown1a", 0xFFFFFFFF, i);
  8486. p->setArrayDataByName("coin_copper", mail->coin_copper, i);
  8487. p->setArrayDataByName("coin_silver", mail->coin_silver, i);
  8488. p->setArrayDataByName("coin_gold", mail->coin_gold, i);
  8489. p->setArrayDataByName("coin_plat", mail->coin_plat, i);
  8490. //p->setArrayDataByName("unknown2", 0, i);
  8491. bool successItemAdd = false;
  8492. if (mail->stack || mail->char_item_id)
  8493. {
  8494. Item* item = master_item_list.GetItem(mail->char_item_id);
  8495. if (item)
  8496. {
  8497. item->stack_count = mail->stack > 1 ? mail->stack : 0;
  8498. if (version < 860)
  8499. p->setItemArrayDataByName("item", item, player, i, 0, GetClientItemPacketOffset());
  8500. else if (version < 1193)
  8501. p->setItemArrayDataByName("item", item, player, i);
  8502. else
  8503. p->setItemArrayDataByName("item", item, player, i, 0, 2);
  8504. successItemAdd = true;
  8505. }
  8506. }
  8507. if (!successItemAdd)
  8508. {
  8509. p->setArrayDataByName("end_tag2", GetItemPacketType(GetVersion()), i);
  8510. p->setArrayDataByName("end_tag3", 0xFF, i);
  8511. }
  8512. i++;
  8513. }
  8514. // GMs send mail for free!
  8515. if (GetAdminStatus() > 0)
  8516. {
  8517. p->setDataByName("postage_cost", 0);
  8518. p->setDataByName("attachment_cost", 0);
  8519. }
  8520. else
  8521. {
  8522. p->setDataByName("postage_cost", 10);
  8523. p->setDataByName("attachment_cost", 50);
  8524. }
  8525. p->setDataByName("unknown3", 0x01F4);
  8526. p->setDataByName("unknown4", 0x01000000);
  8527. EQ2Packet* pack = p->serialize();
  8528. //DumpPacket(pack);
  8529. QueuePacket(pack);
  8530. safe_delete(p);
  8531. }
  8532. }
  8533. else
  8534. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8535. }
  8536. void Client::DisplayMailMessage(int32 mail_id) {
  8537. Mail* mail = player->GetMail(mail_id);
  8538. if (mail) {
  8539. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  8540. if (kiosk_id > 0) {
  8541. PacketStruct* update = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8542. if (update) {
  8543. update->setDataByName("action", 0x03);
  8544. update->setDataByName("packettype", GetItemPacketType(GetVersion()));
  8545. update->setDataByName("packetsubtype", 0xFF);
  8546. QueuePacket(update->serialize());
  8547. safe_delete(update);
  8548. }
  8549. if (!mail->already_read) {
  8550. mail->already_read = true;
  8551. SendMailList();
  8552. }
  8553. PacketStruct* packet = configReader.getStruct("WS_MailGetMessage", GetVersion());
  8554. if (packet) {
  8555. packet->setDataByName("kiosk_id", kiosk_id);
  8556. packet->setDataByName("mail_id", mail->mail_id);
  8557. packet->setDataByName("player_to_id", mail->player_to_id);
  8558. packet->setDataByName("player_from", mail->player_from.c_str());
  8559. packet->setDataByName("subject", mail->subject.c_str());
  8560. packet->setDataByName("mail_body", mail->mail_body.c_str());
  8561. packet->setDataByName("unknown1", 1);
  8562. packet->setDataByName("unknown2", 0);
  8563. packet->setDataByName("lock_report_button", 1);
  8564. packet->setDataByName("unknown3", 0xFFFFFFFF);
  8565. packet->setDataByName("unknown3a", 0xFFFFFFFF);
  8566. packet->setDataByName("coin_copper", mail->coin_copper);
  8567. packet->setDataByName("coin_silver", mail->coin_silver);
  8568. packet->setDataByName("coin_gold", mail->coin_gold);
  8569. packet->setDataByName("coin_plat", mail->coin_plat);
  8570. if (mail->stack || mail->char_item_id)
  8571. {
  8572. Item* item = master_item_list.GetItem(mail->char_item_id);
  8573. item->stack_count = mail->stack > 1 ? mail->stack : 0;
  8574. if (version < 860)
  8575. packet->setItemByName("item", item, player, 0, version <= 373 ? -2 : -1);
  8576. else if (version < 1193)
  8577. packet->setItemByName("item", item, player, 0, 0);
  8578. else
  8579. packet->setItemByName("item", item, player, 0, 2);
  8580. }
  8581. else
  8582. {
  8583. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  8584. packet->setDataByName("end_tag3", 0xFF);
  8585. }
  8586. mail->save_needed = true;
  8587. EQ2Packet* pack = packet->serialize();
  8588. QueuePacket(pack);
  8589. safe_delete(packet);
  8590. // trying to update this causes the window not to open
  8591. //SendMailList();
  8592. }
  8593. }
  8594. else
  8595. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8596. }
  8597. }
  8598. /* 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
  8599. packet back to the client before the mail actually sent. */
  8600. void Client::HandleSentMail(EQApplicationPacket* app) {
  8601. PacketStruct* packet = configReader.getStruct("WS_MailSendMessage", GetVersion());
  8602. if (packet) {
  8603. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  8604. string player_to = packet->getType_EQ2_16BitString_ByName("player_to").data;
  8605. PacketStruct* reply_packet = configReader.getStruct("WS_MailSendMessageReply", GetVersion());
  8606. vector<int32>* ids = 0;
  8607. MMailWindowMutex.lock();
  8608. if (reply_packet) {
  8609. int8 reply_type = MAIL_SEND_RESULT_UNKNOWN_ERROR;
  8610. if (player_to.length() == 0)
  8611. reply_type = MAIL_SEND_RESULT_EMPTY_TO_LIST;
  8612. else if (player_to.compare(string(GetPlayer()->GetName())) == 0)
  8613. reply_type = MAIL_SEND_RESULT_CANNOT_SEND_TO_SELF;
  8614. else if (GetAdminStatus() == 0 && !player->RemoveCoins(10))
  8615. reply_type = MAIL_SEND_RESULT_NOT_ENOUGH_COIN;
  8616. else {
  8617. if (GetAdminStatus() > 200 && player_to.compare("<all>") == 0) {
  8618. if (mail_window.char_item_id == 0 && (mail_window.coin_copper + mail_window.coin_silver + mail_window.coin_gold + mail_window.coin_plat) == 0)
  8619. ids = database.GetAllPlayerIDs();
  8620. else
  8621. SimpleMessage(CHANNEL_NARRATIVE, "You may not mail gifts to multiple players.");
  8622. }
  8623. else {
  8624. ids = new vector<int32>;
  8625. ids->push_back(database.GetCharacterID(player_to.c_str()));
  8626. }
  8627. if (ids) {
  8628. for (int32 i = 0; i < ids->size(); i++) {
  8629. int32 player_to_id = ids->at(i);
  8630. if (player_to_id > 0) {
  8631. reply_type = MAIL_SEND_RESULT_SUCCESS;
  8632. Mail* mail = new Mail;
  8633. mail->mail_id = 0;
  8634. mail->player_to_id = player_to_id;
  8635. mail->player_from = string(GetPlayer()->GetName());
  8636. mail->subject = packet->getType_EQ2_16BitString_ByName("subject").data;
  8637. mail->mail_body = packet->getType_EQ2_16BitString_ByName("mail_body").data;
  8638. mail->already_read = 0;
  8639. mail->mail_type = MAIL_TYPE_REGULAR;
  8640. mail->coin_copper = mail_window.coin_copper;
  8641. mail->coin_silver = mail_window.coin_silver;
  8642. mail->coin_gold = mail_window.coin_gold;
  8643. mail->coin_plat = mail_window.coin_plat;
  8644. mail->char_item_id = mail_window.char_item_id;
  8645. mail->stack = mail_window.stack;
  8646. // GM's send mail for free!
  8647. if (GetAdminStatus() > 0)
  8648. {
  8649. mail->postage_cost = 0;
  8650. mail->attachment_cost = 0;
  8651. }
  8652. else
  8653. {
  8654. mail->postage_cost = 10;
  8655. mail->attachment_cost = 50;
  8656. }
  8657. mail->time_sent = Timer::GetUnixTimeStamp();
  8658. mail->expire_time = mail->time_sent + 2592000; //30 days in seconds
  8659. mail->save_needed = false;
  8660. database.SavePlayerMail(mail);
  8661. Client* to_client = zone_list.GetClientByCharID(player_to_id);
  8662. if (to_client) {
  8663. to_client->GetPlayer()->AddMail(mail);
  8664. to_client->SimpleMessage(CHANNEL_NARRATIVE, "You have unread mail in your mailbox.");
  8665. string popup_text = "You have unread mail!";
  8666. to_client->SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  8667. }
  8668. else {
  8669. // don't need the pointer the client doesn't exist currently
  8670. safe_delete(mail);
  8671. }
  8672. ResetSendMail(false, false);
  8673. }
  8674. else
  8675. reply_type = MAIL_SEND_RESULT_UNKNOWN_PLAYER;
  8676. }
  8677. }
  8678. }
  8679. string players_to = "";
  8680. if (ids) {
  8681. for (int32 i = 0; i < ids->size(); i++) {
  8682. if (ids->at(i) != 0)
  8683. players_to.append(database.GetCharacterName(ids->at(i)));
  8684. if (i < (ids->size() - 1))
  8685. players_to.append(", ");
  8686. }
  8687. }
  8688. reply_packet->setDataByName("player_to", players_to.c_str());
  8689. reply_packet->setDataByName("reply_type", reply_type);
  8690. QueuePacket(reply_packet->serialize());
  8691. safe_delete(reply_packet);
  8692. safe_delete(ids);
  8693. }
  8694. MMailWindowMutex.unlock();
  8695. }
  8696. safe_delete(packet);
  8697. }
  8698. }
  8699. void Client::DeleteMail(int32 mail_id, bool from_database) {
  8700. player->DeleteMail(mail_id, from_database);
  8701. }
  8702. bool Client::AddMailItem(Item* item)
  8703. {
  8704. if (item && (item->CheckFlag(LORE) || item->CheckFlag(STACK_LORE))) {
  8705. Message(CHANNEL_COLOR_CHAT_RELATIONSHIP, "Lore items cannot be mailed.");
  8706. return false;
  8707. }
  8708. bool ret = false;
  8709. if (GetMailTransaction()) {
  8710. MMailWindowMutex.lock();
  8711. if (mail_window.char_item_id == 0)
  8712. {
  8713. mail_window.item = item;
  8714. mail_window.char_item_id = item->details.item_id;
  8715. mail_window.stack = item->details.count;
  8716. ret = true;
  8717. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8718. packet->setDataByName("coin_copper", mail_window.coin_copper);
  8719. packet->setDataByName("coin_silver", mail_window.coin_silver);
  8720. packet->setDataByName("coin_gold", mail_window.coin_gold);
  8721. packet->setDataByName("coin_plat", mail_window.coin_plat);
  8722. if (item)
  8723. {
  8724. packet->setDataByName("stack", mail_window.stack);
  8725. item->stack_count = mail_window.stack;
  8726. if (version < 860)
  8727. packet->setItemByName("item", item, player, 0, version <= 373 ? -2 : -1);
  8728. else if (version < 1193)
  8729. packet->setItemByName("item", item, player, 0, 0);
  8730. else
  8731. packet->setItemByName("item", item, player, 0, 2);
  8732. }
  8733. else
  8734. {
  8735. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  8736. packet->setDataByName("end_tag3", 0xFF);
  8737. }
  8738. QueuePacket(packet->serialize());
  8739. }
  8740. MMailWindowMutex.unlock();
  8741. }
  8742. return ret;
  8743. }
  8744. bool Client::AddMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  8745. bool ret = false;
  8746. if (GetMailTransaction()) {
  8747. MMailWindowMutex.lock();
  8748. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8749. if (packet) {
  8750. if (copper > 0) {
  8751. if (player->RemoveCoins(copper)) {
  8752. mail_window.coin_copper += copper;
  8753. Message(CHANNEL_NARRATIVE, "You add %u copper to the mail window.", copper);
  8754. ret = true;
  8755. }
  8756. }
  8757. else if (silver > 0) {
  8758. if (player->RemoveCoins(silver * 100)) {
  8759. mail_window.coin_silver += silver;
  8760. Message(CHANNEL_NARRATIVE, "You add %u silver to the mail window.", silver);
  8761. ret = true;
  8762. }
  8763. }
  8764. else if (gold > 0) {
  8765. if (player->RemoveCoins(gold * 10000)) {
  8766. mail_window.coin_gold += gold;
  8767. Message(CHANNEL_NARRATIVE, "You add %u gold to the mail window.", gold);
  8768. ret = true;
  8769. }
  8770. }
  8771. else if (plat > 0) {
  8772. if (player->RemoveCoins(plat * 1000000)) {
  8773. mail_window.coin_plat += plat;
  8774. Message(CHANNEL_NARRATIVE, "You add %u platinum to the mail window.", plat);
  8775. ret = true;
  8776. }
  8777. }
  8778. if (ret) {
  8779. packet->setDataByName("coin_copper", mail_window.coin_copper);
  8780. packet->setDataByName("coin_silver", mail_window.coin_silver);
  8781. packet->setDataByName("coin_gold", mail_window.coin_gold);
  8782. packet->setDataByName("coin_plat", mail_window.coin_plat);
  8783. Item* item = master_item_list.GetItem(mail_window.char_item_id);
  8784. if (item)
  8785. {
  8786. packet->setDataByName("stack", mail_window.stack);
  8787. item->stack_count = mail_window.stack;
  8788. if (version < 860)
  8789. packet->setItemByName("item", item, player, 0, version <= 373 ? -2 : -1);
  8790. else if (version < 1193)
  8791. packet->setItemByName("item", item, player, 0, 0);
  8792. else
  8793. packet->setItemByName("item", item, player, 0, 2);
  8794. }
  8795. else
  8796. {
  8797. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  8798. packet->setDataByName("end_tag3", 0xFF);
  8799. }
  8800. //packet->PrintPacket();
  8801. QueuePacket(packet->serialize());
  8802. }
  8803. else
  8804. SimpleMessage(CHANNEL_NARRATIVE, "You don't have that much money.");
  8805. safe_delete(packet);
  8806. }
  8807. MMailWindowMutex.unlock();
  8808. }
  8809. else
  8810. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8811. return ret;
  8812. }
  8813. bool Client::RemoveMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  8814. bool ret = false;
  8815. if (GetMailTransaction()) {
  8816. MMailWindowMutex.lock();
  8817. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8818. if (packet) {
  8819. if (copper > 0) {
  8820. player->AddCoins(copper);
  8821. mail_window.coin_copper -= copper;
  8822. Message(CHANNEL_NARRATIVE, "You remove %u copper from the mail window.", copper);
  8823. ret = true;
  8824. }
  8825. else if (silver > 0) {
  8826. player->AddCoins(silver * 100);
  8827. mail_window.coin_silver -= silver;
  8828. Message(CHANNEL_NARRATIVE, "You remove %u silver from the mail window.", silver);
  8829. ret = true;
  8830. }
  8831. else if (gold > 0) {
  8832. player->AddCoins(gold * 10000);
  8833. mail_window.coin_gold -= gold;
  8834. Message(CHANNEL_NARRATIVE, "You remove %u gold from the mail window.", gold);
  8835. ret = true;
  8836. }
  8837. else if (plat > 0) {
  8838. player->AddCoins(plat * 1000000);
  8839. mail_window.coin_plat -= plat;
  8840. Message(CHANNEL_NARRATIVE, "You remove %u platinum from the mail window.", plat);
  8841. ret = true;
  8842. }
  8843. if (ret) {
  8844. packet->setDataByName("coin_copper", mail_window.coin_copper);
  8845. packet->setDataByName("coin_silver", mail_window.coin_silver);
  8846. packet->setDataByName("coin_gold", mail_window.coin_gold);
  8847. packet->setDataByName("coin_plat", mail_window.coin_plat);
  8848. packet->setDataByName("stack", 0);
  8849. packet->setDataByName("packettype", 0x2BFE);
  8850. packet->setDataByName("packetsubtype", 0xFF);
  8851. packet->setDataByName("unknown2", 0);
  8852. QueuePacket(packet->serialize());
  8853. }
  8854. safe_delete(packet);
  8855. }
  8856. MMailWindowMutex.unlock();
  8857. }
  8858. else
  8859. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8860. return ret;
  8861. }
  8862. void Client::TakeMailAttachments(int32 mail_id) {
  8863. if (GetMailTransaction()) {
  8864. Mail* mail = player->GetMail(mail_id);
  8865. if (mail) {
  8866. int64 amount = 0;
  8867. if (mail->coin_copper > 0) {
  8868. amount += mail->coin_copper;
  8869. mail->coin_copper = 0;
  8870. }
  8871. if (mail->coin_silver > 0) {
  8872. amount += mail->coin_silver * 100;
  8873. mail->coin_silver = 0;
  8874. }
  8875. if (mail->coin_gold > 0) {
  8876. amount += mail->coin_gold * 10000;
  8877. mail->coin_gold = 0;
  8878. }
  8879. if (mail->coin_plat > 0) {
  8880. amount += mail->coin_plat * 1000000;
  8881. mail->coin_plat = 0;
  8882. }
  8883. if (mail->char_item_id > 0) {
  8884. AddItem(mail->char_item_id, mail->stack);
  8885. mail->char_item_id = 0;
  8886. mail->stack = 0;
  8887. }
  8888. /* 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
  8889. the mail the player is getting attachments from. There is an opcode OP_MailRemoveAttachFromMailMsg with opcode 328 but i can't
  8890. find it in any packet logs.*/
  8891. /*PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8892. if (packet) {
  8893. packet->setDataByName("unknown", 0x03);
  8894. packet->setDataByName("coin_copper", mail->coin_copper);
  8895. packet->setDataByName("coin_silver", mail->coin_silver);
  8896. packet->setDataByName("coin_gold", mail->coin_gold);
  8897. packet->setDataByName("coin_plat", mail->coin_plat);
  8898. packet->setDataByName("stack", 0);
  8899. packet->setDataByName("packettype", 0x2BFE);
  8900. packet->setDataByName("packetsubtype", 0xFF);
  8901. packet->setDataByName("unknown2", 0);
  8902. packet->setDataByName("unknown3", 0x00000001);//0x00000016
  8903. DumpPacket(packet->serialize());
  8904. QueuePacket(packet->serialize());
  8905. safe_delete(packet);
  8906. }*/
  8907. database.SavePlayerMail(mail);
  8908. if (amount > 0)
  8909. player->AddCoins(amount);
  8910. SendMailList();
  8911. }
  8912. }
  8913. else
  8914. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8915. }
  8916. void Client::ResetSendMail(bool cancel, bool needslock) {
  8917. if (cancel && mail_transaction)
  8918. SimpleMessage(CHANNEL_NARRATIVE, "You cancel sending a letter.");
  8919. if (needslock)
  8920. MMailWindowMutex.lock();
  8921. if (cancel)
  8922. player->AddCoins(mail_window.coin_copper + (mail_window.coin_silver * 100) + (mail_window.coin_gold * 10000) + (mail_window.coin_plat * 1000000));
  8923. if (!cancel)
  8924. mail_transaction = 0;
  8925. mail_window.coin_copper = 0;
  8926. mail_window.coin_silver = 0;
  8927. mail_window.coin_gold = 0;
  8928. mail_window.coin_plat = 0;
  8929. mail_window.char_item_id = 0;
  8930. mail_window.stack = 0;
  8931. if (mail_window.item) {
  8932. if (cancel)
  8933. AddItem(mail_window.item);
  8934. else
  8935. safe_delete(mail_window.item);
  8936. }
  8937. mail_window.item = nullptr;
  8938. if (needslock)
  8939. MMailWindowMutex.unlock();
  8940. }
  8941. bool Client::GateAllowed() {
  8942. ZoneServer* zone = GetCurrentZone();
  8943. if (zone) {
  8944. bool cangate = zone->GetCanGate();
  8945. return cangate;
  8946. }
  8947. return false;
  8948. }
  8949. bool Client::BindAllowed() {
  8950. ZoneServer* zone = GetCurrentZone();
  8951. if (zone) {
  8952. bool canbind = zone->GetCanBind();
  8953. return canbind;
  8954. }
  8955. return false;
  8956. }
  8957. bool Client::Bind() {
  8958. int canbind = BindAllowed();
  8959. if (canbind == 0) {
  8960. Message(CHANNEL_MERCHANT, "You cannot bind at this location.");
  8961. return false;
  8962. }
  8963. player->GetPlayerInfo()->SetBindZone(GetCurrentZone()->GetZoneID());
  8964. player->GetPlayerInfo()->SetBindX(player->GetX());
  8965. player->GetPlayerInfo()->SetBindY(player->GetY());
  8966. player->GetPlayerInfo()->SetBindZ(player->GetZ());
  8967. player->GetPlayerInfo()->SetBindHeading(player->GetHeading());
  8968. Message(CHANNEL_MERCHANT, "Your spirit has been bound to this location.");
  8969. return true;
  8970. }
  8971. bool Client::Gate(bool is_spell) {
  8972. if (player->GetPlayerInfo()->GetBindZoneID() == 0) {
  8973. SimpleMessage(CHANNEL_MERCHANT, "You can not cast recall spells. You have no bind location set.");
  8974. return false;
  8975. }
  8976. ZoneChangeDetails zone_details;
  8977. if (zone_list.GetZone(&zone_details, player->GetPlayerInfo()->GetBindZoneID())) {
  8978. int cangate = GateAllowed();
  8979. if (cangate == 0) {
  8980. SimpleMessage(CHANNEL_MERCHANT, "You can not cast recall spells in this zone.");
  8981. return false;
  8982. }
  8983. player->SetX(player->GetPlayerInfo()->GetBindZoneX());
  8984. player->SetY(player->GetPlayerInfo()->GetBindZoneY());
  8985. player->SetZ(player->GetPlayerInfo()->GetBindZoneZ());
  8986. player->SetHeading(player->GetPlayerInfo()->GetBindZoneHeading());
  8987. Zone(&zone_details, (ZoneServer*)zone_details.zonePtr, false, is_spell);
  8988. return true;
  8989. }
  8990. return false;
  8991. }
  8992. void Client::ProcessTeleport(Spawn* spawn, vector<TransportDestination*>* destinations, int32 transport_id, bool is_spell) {
  8993. if (!destinations || !spawn) {
  8994. return;
  8995. }
  8996. bool has_map = false;
  8997. if (transport_id > 0)
  8998. has_map = GetCurrentZone()->TransportHasMap(transport_id);
  8999. transport_spawn = spawn;
  9000. vector<TransportDestination*> transport_list;
  9001. vector<TransportDestination*>::iterator itr;
  9002. TransportDestination* destination = 0;
  9003. for (itr = destinations->begin(); itr != destinations->end(); itr++) {
  9004. destination = *itr;
  9005. 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)))
  9006. transport_list.push_back(destination);
  9007. }
  9008. if (transport_list.size() == 0 && destination) {
  9009. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  9010. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  9011. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  9012. else
  9013. {
  9014. EQ2Packet* app = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  9015. if (app)
  9016. QueuePacket(app);
  9017. }
  9018. }
  9019. else {
  9020. // determine if this is an instanced zone that already exists
  9021. ZoneChangeDetails zone_details;
  9022. bool foundZone = world.GetGroupManager()->IdentifyMemberInGroupOrRaid(&zone_details, this, destination->destination_zone_id);
  9023. if (foundZone) {
  9024. GetPlayer()->SetX(destination->destination_x);
  9025. GetPlayer()->SetY(destination->destination_y);
  9026. GetPlayer()->SetZ(destination->destination_z);
  9027. GetPlayer()->SetHeading(destination->destination_heading);
  9028. Zone(&zone_details, (ZoneServer*)zone_details.zonePtr, false, is_spell);
  9029. }
  9030. else {
  9031. bool isZone = zone_list.GetZone(&zone_details, destination->destination_zone_id);
  9032. if (isZone) {
  9033. GetPlayer()->SetX(destination->destination_x);
  9034. GetPlayer()->SetY(destination->destination_y);
  9035. GetPlayer()->SetZ(destination->destination_z);
  9036. GetPlayer()->SetHeading(destination->destination_heading);
  9037. Zone(&zone_details, (ZoneServer*)zone_details.zonePtr, false, is_spell);
  9038. }
  9039. else {
  9040. SimpleMessage(CHANNEL_COLOR_RED, "Error establishing a zone destination");
  9041. }
  9042. }
  9043. }
  9044. if (destination->message.length() > 0)
  9045. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  9046. }
  9047. else if (transport_list.size() > 0) {
  9048. if (!spawn->IsSoundsDisabled())
  9049. PlaySound("mariner_bell");
  9050. PacketStruct* packet = configReader.getStruct("WS_TeleportList", GetVersion());
  9051. if (packet) {
  9052. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  9053. // Put all the destinations the player can go in a new vector
  9054. vector<TransportDestination*> destinations;
  9055. for (int32 i = 0; i < transport_list.size(); i++) {
  9056. destination = transport_list.at(i);
  9057. // Check min level
  9058. if (destination->min_level > 0 && GetPlayer()->GetLevel() < destination->min_level)
  9059. continue;
  9060. // Check max level
  9061. if (destination->max_level > 0 && GetPlayer()->GetLevel() > destination->max_level)
  9062. continue;
  9063. // Check quest complete
  9064. if (destination->req_quest_complete > 0 && GetPlayer()->HasQuestBeenCompleted(destination->req_quest_complete) == 0)
  9065. continue;
  9066. // Check req quest and step
  9067. if (destination->req_quest > 0 && destination->req_quest_step > 0 && GetPlayer()->GetQuestStep(destination->req_quest) != destination->req_quest_step)
  9068. continue;
  9069. // 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
  9070. if (has_map && (destination->destination_zone_id == GetCurrentZone()->GetZoneID() && GetPlayer()->GetDistance(destination->destination_x, destination->destination_y, destination->destination_z) < 20)) {
  9071. packet->setDataByName("current_zone", destination->display_name.c_str());
  9072. packet->setDataByName("current_map_x", destination->map_x);
  9073. packet->setDataByName("current_map_y", destination->map_y);
  9074. }
  9075. else {
  9076. destinations.push_back(destination);
  9077. }
  9078. }
  9079. // Use the new vector to create the packet
  9080. destination = 0;
  9081. packet->setArrayLengthByName("num_destinations", destinations.size());
  9082. for (int32 i = 0; i < destinations.size(); i++) {
  9083. destination = destinations.at(i);
  9084. packet->setArrayDataByName("unique_id", destination->unique_id, i);
  9085. packet->setArrayDataByName("display_name", destination->display_name.c_str(), i);
  9086. packet->setArrayDataByName("zone_name", destination->display_name.c_str(), i);
  9087. packet->setArrayDataByName("zone_file_name", destination->display_name.c_str(), i);
  9088. packet->setArrayDataByName("cost", destination->cost, i);
  9089. if (has_map) {
  9090. packet->setArrayDataByName("map_x", destination->map_x, i);
  9091. packet->setArrayDataByName("map_y", destination->map_y, i);
  9092. }
  9093. }
  9094. if (has_map)
  9095. packet->setDataByName("map_name", GetCurrentZone()->GetTransportMap(transport_id).c_str());
  9096. EQ2Packet* app = packet->serialize();
  9097. //DumpPacket(app);
  9098. if (destinations.size() > 0)
  9099. QueuePacket(app);
  9100. safe_delete(packet);
  9101. }
  9102. }
  9103. }
  9104. void Client::ProcessTeleportLocation(EQApplicationPacket* app) {
  9105. PacketStruct* packet = configReader.getStruct("WS_TeleportDestination", GetVersion());
  9106. if (packet) {
  9107. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  9108. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(packet->getType_int32_ByName("spawn_id"));
  9109. int32 unique_id = packet->getType_int32_ByName("unique_id");
  9110. string zone_name = packet->getType_EQ2_16BitString_ByName("zone_name").data;
  9111. int32 cost = packet->getType_int32_ByName("cost");
  9112. vector<TransportDestination*> destinations;
  9113. TransportDestination* destination = 0;
  9114. if (this->GetTemporaryTransportID() || (spawn && spawn == transport_spawn && spawn->GetTransporterID()))
  9115. GetCurrentZone()->GetTransporters(&destinations, this, this->GetTemporaryTransportID() ? this->GetTemporaryTransportID() : spawn->GetTransporterID());
  9116. vector<TransportDestination*>::iterator itr;
  9117. for (itr = destinations.begin(); itr != destinations.end(); itr++) {
  9118. if ((*itr)->unique_id == unique_id && (*itr)->display_name == zone_name && (*itr)->cost == cost) {
  9119. destination = *itr;
  9120. break;
  9121. }
  9122. }
  9123. SetTemporaryTransportID(0);
  9124. if (!destination)
  9125. SimpleMessage(CHANNEL_COLOR_RED, "Error processing transport.");
  9126. else {
  9127. if (cost == 0 || player->RemoveCoins(cost)) {
  9128. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  9129. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  9130. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  9131. else
  9132. {
  9133. EQ2Packet* outapp = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  9134. if (outapp)
  9135. QueuePacket(outapp);
  9136. }
  9137. }
  9138. else {
  9139. GetPlayer()->SetX(destination->destination_x);
  9140. GetPlayer()->SetY(destination->destination_y);
  9141. GetPlayer()->SetZ(destination->destination_z);
  9142. GetPlayer()->SetHeading(destination->destination_heading);
  9143. // Test if where we're going is an Instanced zone
  9144. if (!TryZoneInstance(destination->destination_zone_id, false)) {
  9145. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Attempting to zone normally");
  9146. ZoneChangeDetails zone_details;
  9147. if (zone_list.GetZone(&zone_details, destination->destination_zone_id)) {
  9148. Zone(&zone_details, (ZoneServer*)zone_details.zonePtr, false);
  9149. }
  9150. }
  9151. }
  9152. if (destination->message.length() > 0)
  9153. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  9154. }
  9155. else
  9156. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough money to use this transport.");
  9157. }
  9158. }
  9159. safe_delete(packet);
  9160. }
  9161. }
  9162. void Client::SendNewSpells(int8 class_id) {
  9163. if (class_id > 0) {
  9164. vector<Spell*>* spells = master_spell_list.GetSpellListByAdventureClass(class_id, player->GetLevel(), 1);
  9165. AddSendNewSpells(spells);
  9166. safe_delete(spells);
  9167. }
  9168. }
  9169. void Client::SendNewTSSpells(int8 class_id) {
  9170. if (class_id > 0) {
  9171. vector<Spell*>* spells = master_spell_list.GetSpellListByTradeskillClass(class_id, player->GetLevel(), 1);
  9172. AddSendNewSpells(spells);
  9173. safe_delete(spells);
  9174. }
  9175. }
  9176. void Client::AddSendNewSpells(vector<Spell*>* spells) {
  9177. Spell* spell = 0;
  9178. bool send_updates = false;
  9179. vector<Spell*>::iterator itr;
  9180. for (itr = spells->begin(); itr != spells->end(); itr++) {
  9181. spell = *itr;
  9182. if (spell && !player->HasSpell(spell->GetSpellID(), spell->GetSpellTier(), true) && spell->GetSpellData()->lua_script.length() > 0) {
  9183. send_updates = true;
  9184. SendSpellUpdate(spell);
  9185. player->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), player->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  9186. player->UnlockSpell(spell);
  9187. }
  9188. }
  9189. if (send_updates) {
  9190. EQ2Packet* outapp = player->GetSpellBookUpdatePacket(GetVersion());
  9191. if (outapp)
  9192. QueuePacket(outapp);
  9193. }
  9194. }
  9195. void Client::SetItemSearch(vector<Item*>* items) {
  9196. if (items) {
  9197. safe_delete(search_items);
  9198. search_items = items;
  9199. }
  9200. }
  9201. vector<Item*>* Client::GetSearchItems() {
  9202. return search_items;
  9203. }
  9204. void Client::SearchStore(int32 page) {
  9205. if (search_items) {
  9206. PacketStruct* packet = configReader.getStruct("WS_BrokerItems", GetVersion());
  9207. if (packet) {
  9208. int32 x = page * 8;
  9209. if (search_items->size() > 8) {
  9210. if ((search_items->size() - x) > 8)
  9211. packet->setArrayLengthByName("num_items", 8);
  9212. else
  9213. packet->setArrayLengthByName("num_items", search_items->size() - x);
  9214. }
  9215. else
  9216. packet->setArrayLengthByName("num_items", search_items->size());
  9217. if (search_items->size() > 0) {
  9218. packet->setArrayLengthByName("num_sellers", 1);
  9219. packet->setArrayDataByName("seller_seller_id", 1);
  9220. packet->setDataByName("per_page", 8);
  9221. packet->setDataByName("num_pages", search_items->size() / 8 + 1);
  9222. packet->setDataByName("page", page);
  9223. Item* item = 0;
  9224. int32 limit = search_items->size() > 8 ? 8 : search_items->size();
  9225. for (int32 i = 0; i < limit; i++, x++) {
  9226. if (x >= search_items->size())
  9227. break;
  9228. item = search_items->at(x);
  9229. std::string teststr("test ");
  9230. teststr.append(std::to_string(i));
  9231. packet->setArrayDataByName("string_one", teststr.c_str(), i);
  9232. packet->setArrayDataByName("string_two", "testtwo", i);
  9233. packet->setArrayDataByName("seller_name", "EQ2EMuDev", i);
  9234. packet->setArrayDataByName("item_id", item->details.item_id, i);
  9235. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  9236. packet->setArrayDataByName("icon", item->GetIcon(GetVersion()), i);
  9237. //packet->setArrayDataByName("unknown2b", i, i);
  9238. packet->setArrayDataByName("item_seller_id", 1, i);
  9239. if (item->stack_count == 0)
  9240. packet->setArrayDataByName("quantity", 1, i);
  9241. else
  9242. packet->setArrayDataByName("quantity", item->stack_count, i);
  9243. packet->setArrayDataByName("stack_size", item->stack_count, i);
  9244. packet->setArrayDataByName("sell_price", item->sell_price, i);
  9245. std::string tmpStr("");
  9246. tmpStr.append(item->name.c_str());
  9247. tmpStr.append(" (");
  9248. tmpStr.append(std::to_string(item->details.item_id));
  9249. tmpStr.append(")");
  9250. packet->setArrayDataByName("item_name", tmpStr.c_str(), i);
  9251. packet->setArrayDataByName("req_level", item->generic_info.adventure_default_level, i);
  9252. //QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  9253. }
  9254. }
  9255. EQ2Packet* outapp = packet->serialize();
  9256. //DumpPacket(outapp);
  9257. QueuePacket(outapp);
  9258. safe_delete(packet);
  9259. }
  9260. }
  9261. }
  9262. void Client::SetReadyForUpdates() {
  9263. if (!ready_for_updates) {
  9264. database.loadCharacterProperties(this);
  9265. SendDefaultGroupOptions();
  9266. }
  9267. ready_for_updates = true;
  9268. if (GetVersion() <= 561) {
  9269. SendRecipeList();
  9270. }
  9271. }
  9272. void Client::SetReadyForSpawns(bool val) {
  9273. ready_for_spawns = val;
  9274. if (GetPlayer()->GetActivityStatus() > 0) {
  9275. GetPlayer()->SetActivityStatus(0);
  9276. if (GetPlayer()->GetGroupMemberInfo()) {
  9277. world.GetGroupManager()->GroupMessage(GetPlayer()->GetGroupMemberInfo()->group_id, "%s has returned from Linkdead.", GetPlayer()->GetName());
  9278. }
  9279. }
  9280. GetPlayer()->SetActiveReward(false);
  9281. zone_list.CheckFriendZoned(this);
  9282. }
  9283. void Client::SendChatRelationship(int8 type, const char* name) {
  9284. if (!name) {
  9285. return;
  9286. }
  9287. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  9288. if (packet) {
  9289. packet->setDataByName("account_id", GetAccountID());
  9290. packet->setDataByName("type", type);
  9291. packet->setArrayLengthByName("num_names", 1);
  9292. packet->setArrayDataByName("name", name);
  9293. if (type == 0) {
  9294. Client* client = zone_list.GetClientByCharName(name);
  9295. if (client) {
  9296. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName());
  9297. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()));
  9298. }
  9299. }
  9300. QueuePacket(packet->serialize());
  9301. safe_delete(packet);
  9302. }
  9303. }
  9304. void Client::SendFriendList() {
  9305. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  9306. if (packet) {
  9307. packet->setDataByName("account_id", GetAccountID());
  9308. map<string, int8>::iterator itr;
  9309. map<string, int8>* friends = player->GetFriends();
  9310. if (friends && friends->size() > 0) {
  9311. Client* client = 0;
  9312. vector<string> names;
  9313. for (itr = friends->begin(); itr != friends->end(); itr++) {
  9314. if (itr->second == 2)
  9315. continue;
  9316. names.push_back(itr->first);
  9317. }
  9318. packet->setArrayLengthByName("num_names", names.size());
  9319. for (int32 i = 0; i < names.size(); i++) {
  9320. client = zone_list.GetClientByCharName(names[i]);
  9321. packet->setArrayDataByName("name", names[i].c_str(), i);
  9322. if (client) {
  9323. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName(), i);
  9324. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()), i);
  9325. }
  9326. }
  9327. }
  9328. QueuePacket(packet->serialize());
  9329. safe_delete(packet);
  9330. }
  9331. }
  9332. void Client::SendIgnoreList() {
  9333. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  9334. if (packet) {
  9335. packet->setDataByName("account_id", GetAccountID());
  9336. packet->setDataByName("type", 2);
  9337. map<string, int8>::iterator itr;
  9338. map<string, int8>* ignored = player->GetIgnoredPlayers();
  9339. if (ignored && ignored->size() > 0) {
  9340. vector<string> names;
  9341. for (itr = ignored->begin(); itr != ignored->end(); itr++) {
  9342. if (itr->second == 2)
  9343. continue;
  9344. names.push_back(itr->first);
  9345. }
  9346. packet->setArrayLengthByName("num_names", names.size());
  9347. for (int32 i = 0; i < names.size(); i++)
  9348. packet->setArrayDataByName("name", names[i].c_str(), i);
  9349. }
  9350. QueuePacket(packet->serialize());
  9351. safe_delete(packet);
  9352. }
  9353. }
  9354. void Client::AddWaypoint(string name, int8 type) {
  9355. waypoint_id++;
  9356. WaypointInfo info;
  9357. info.id = waypoint_id;
  9358. info.type = type;
  9359. waypoints[name] = info;
  9360. }
  9361. void Client::SendWaypoints() {
  9362. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  9363. if (packet) {
  9364. packet->setArrayLengthByName("num_updates", waypoints.size());
  9365. map<string, WaypointInfo>::iterator itr;
  9366. int16 i = 0;
  9367. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  9368. packet->setArrayDataByName("waypoint_name", itr->first.c_str(), i);
  9369. packet->setArrayDataByName("waypoint_category", itr->second.type, i);
  9370. packet->setArrayDataByName("spawn_id", itr->second.id, i);
  9371. i++;
  9372. }
  9373. packet->setDataByName("unknown", 0xFFFFFFFF);
  9374. QueuePacket(packet->serialize());
  9375. safe_delete(packet);
  9376. }
  9377. }
  9378. void Client::SelectWaypoint(int32 id) {
  9379. string found_name = "";
  9380. map<string, WaypointInfo>::iterator itr;
  9381. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  9382. if (itr->second.id == id) {
  9383. found_name = itr->first;
  9384. break;
  9385. }
  9386. }
  9387. if (found_name.length() > 0) {
  9388. Spawn* spawn = current_zone->FindSpawn(player, found_name.c_str());
  9389. ShowPathToTarget(spawn);
  9390. }
  9391. }
  9392. void Client::AddWaypoint(const char* waypoint_name, int8 waypoint_category, int32 spawn_id) {
  9393. if (waypoint_name) {
  9394. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  9395. if (packet) {
  9396. packet->setArrayLengthByName("num_updates", 1);
  9397. packet->setArrayDataByName("waypoint_name", waypoint_name, 0);
  9398. packet->setArrayDataByName("waypoint_category", waypoint_category, 0);
  9399. packet->setArrayDataByName("spawn_id", spawn_id, 0);
  9400. packet->setArrayDataByName("waypoint_category2", waypoint_category, 0);
  9401. packet->setArrayDataByName("spawn_id2", spawn_id, 0);
  9402. packet->setDataByName("unknown", 0xFFFFFFFF);
  9403. QueuePacket(packet->serialize());
  9404. safe_delete(packet);
  9405. }
  9406. }
  9407. }
  9408. void Client::ClearWaypoint() {
  9409. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  9410. if (packet) {
  9411. QueuePacket(packet->serialize());
  9412. safe_delete(packet);
  9413. }
  9414. }
  9415. bool Client::ShowPathToTarget(float x, float y, float z, float y_offset) {
  9416. if (current_zone->pathing) {
  9417. if (GetPlayer()->GetMap()) {
  9418. if (x < GetPlayer()->GetMap()->GetMinX() || x > GetPlayer()->GetMap()->GetMaxX())
  9419. return false;
  9420. if (z < GetPlayer()->GetMap()->GetMinZ() || z > GetPlayer()->GetMap()->GetMaxZ())
  9421. return false;
  9422. auto loc = glm::vec3(x, z, y);
  9423. float new_z = GetPlayer()->FindBestZ(loc, nullptr);
  9424. if (new_z != BEST_Z_INVALID) //this is actually y
  9425. y = new_z;
  9426. }
  9427. bool partial = false;
  9428. bool stuck = false;
  9429. PathfinderOptions opts;
  9430. opts.smooth_path = true;
  9431. opts.step_size = 100.0f;//RuleR(Pathing, NavmeshStepSize);
  9432. opts.offset = y_offset + 1.0f;
  9433. opts.flags = PathingNotDisabled ^ PathingZoneLine;
  9434. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  9435. if (packet) {
  9436. auto path = current_zone->pathing->FindPath(glm::vec3(player->GetX(), player->GetZ(), player->GetY()), glm::vec3(x, z, y), partial, stuck, opts);
  9437. packet->setArrayLengthByName("num_points", path.size());
  9438. int i = 0;
  9439. for (auto& node : path)
  9440. {
  9441. packet->setArrayDataByName("x", node.pos.x, i);
  9442. packet->setArrayDataByName("y", node.pos.z, i);
  9443. packet->setArrayDataByName("z", node.pos.y, i);
  9444. packet->setDataByName("waypoint_x", x);
  9445. packet->setDataByName("waypoint_y", y);
  9446. packet->setDataByName("waypoint_z", z);
  9447. i++;
  9448. }
  9449. if (i > 0)
  9450. QueuePacket(packet->serialize());
  9451. safe_delete(packet);
  9452. return (i > 0);
  9453. }
  9454. }
  9455. return false;
  9456. }
  9457. bool Client::ShowPathToTarget(Spawn* spawn) {
  9458. if (spawn) {
  9459. return ShowPathToTarget(spawn->GetX(), spawn->GetY(), spawn->GetZ(), spawn->GetYOffset());
  9460. }
  9461. return false;
  9462. }
  9463. void Client::BeginWaypoint(const char* waypoint_name, float x, float y, float z) {
  9464. if (waypoint_name) {
  9465. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  9466. if (packet) {
  9467. packet->setArrayLengthByName("num_points", 1);
  9468. packet->setArrayDataByName("x", x, 0);
  9469. packet->setArrayDataByName("y", y, 0);
  9470. packet->setArrayDataByName("z", z, 0);
  9471. packet->setDataByName("waypoint_x", x);
  9472. packet->setDataByName("waypoint_y", y);
  9473. packet->setDataByName("waypoint_z", z);
  9474. packet->setDataByName("waypoint_name", waypoint_name);
  9475. packet->setDataByName("unknown", 0);
  9476. QueuePacket(packet->serialize());
  9477. safe_delete(packet);
  9478. }
  9479. }
  9480. }
  9481. void Client::InspectPlayer(Player* player_to_inspect) {
  9482. int source_pvp_alignment = GetPlayer()->GetPVPAlignment();
  9483. int target_pvp_alignment = player_to_inspect->GetPVPAlignment();
  9484. bool pvp_allowed = rule_manager.GetZoneRule(GetCurrentZoneID(), R_PVP, AllowPVP)->GetBool();
  9485. if (pvp_allowed == true) {
  9486. if (source_pvp_alignment != target_pvp_alignment) {
  9487. Message(CHANNEL_COLOR_RED, "You can not inspect players of different alignments.");
  9488. return;
  9489. }
  9490. }
  9491. if (player_to_inspect && player_to_inspect->GetClient()) {
  9492. PacketStruct* packet = configReader.getStruct("WS_InspectPlayer", GetVersion());
  9493. if (packet) {
  9494. packet->setDataByName("unknown", 0);
  9495. packet->setSmallStringByName("name", player_to_inspect->GetName());
  9496. packet->setDataByName("race", player_to_inspect->GetRace());
  9497. packet->setDataByName("gender", player_to_inspect->GetGender());
  9498. packet->setDataByName("adventure_level", player_to_inspect->GetLevel());
  9499. int16 effective_level = player_to_inspect->GetInfoStruct()->get_effective_level() != 0 ? player_to_inspect->GetInfoStruct()->get_effective_level() : player_to_inspect->GetLevel();
  9500. packet->setDataByName("adventure_level_effective", effective_level);
  9501. packet->setDataByName("adventure_class", player_to_inspect->GetAdventureClass());
  9502. packet->setDataByName("tradeskill_level", player_to_inspect->GetTSLevel());
  9503. packet->setDataByName("tradeskill_class", player_to_inspect->GetTradeskillClass());
  9504. packet->setDataByName("health", player_to_inspect->GetHP());
  9505. packet->setDataByName("health_max", player_to_inspect->GetTotalHP());
  9506. packet->setDataByName("health_base", player_to_inspect->GetTotalHPBase());
  9507. packet->setDataByName("power", player_to_inspect->GetPower());
  9508. packet->setDataByName("power_max", player_to_inspect->GetTotalPower());
  9509. packet->setDataByName("power_base", player_to_inspect->GetTotalPowerBase());
  9510. packet->setDataByName("mitigation", player_to_inspect->GetInfoStruct()->get_cur_mitigation());
  9511. packet->setDataByName("unknown1", 0);
  9512. packet->setDataByName("avoidance", player_to_inspect->GetInfoStruct()->get_avoidance_display() * 10.0f);
  9513. packet->setDataByName("unknown2", 0);
  9514. packet->setDataByName("mitigation_percentage", 0);
  9515. packet->setDataByName("strength", player_to_inspect->GetStr());
  9516. packet->setDataByName("strength_base", player_to_inspect->GetStrBase());
  9517. packet->setDataByName("stamina", player_to_inspect->GetSta());
  9518. packet->setDataByName("stamina_base", player_to_inspect->GetStaBase());
  9519. packet->setDataByName("agility", player_to_inspect->GetAgi());
  9520. packet->setDataByName("agility_base", player_to_inspect->GetAgiBase());
  9521. packet->setDataByName("wisdom", player_to_inspect->GetWis());
  9522. packet->setDataByName("wisdom_base", player_to_inspect->GetWisBase());
  9523. packet->setDataByName("intelligence", player_to_inspect->GetInt());
  9524. packet->setDataByName("intelligence_base", player_to_inspect->GetIntBase());
  9525. packet->setDataByName("unknown4", 0);
  9526. packet->setDataByName("unknown5", 0);
  9527. packet->setDataByName("unknown6", 0);
  9528. packet->setDataByName("unknown7", 0);
  9529. packet->setDataByName("unknown8", 0);
  9530. packet->setDataByName("unknown9", 0);
  9531. packet->setDataByName("unknown10", 0);
  9532. packet->setDataByName("unknown11", 0);
  9533. packet->setDataByName("unknown12", 0);
  9534. packet->setDataByName("heat_resist", player_to_inspect->GetHeatResistance());
  9535. packet->setDataByName("heat_resist_base", player_to_inspect->GetHeatResistanceBase());
  9536. packet->setDataByName("heat_resist_percentage", 0);
  9537. packet->setDataByName("cold_resist", player_to_inspect->GetColdResistance());
  9538. packet->setDataByName("cold_resist_base", player_to_inspect->GetColdResistanceBase());
  9539. packet->setDataByName("cold_resist_percentage", 0);
  9540. packet->setDataByName("magic_resist", player_to_inspect->GetMagicResistance());
  9541. packet->setDataByName("magic_resist_base", player_to_inspect->GetMagicResistanceBase());
  9542. packet->setDataByName("magic_resist_percentage", 0);
  9543. packet->setDataByName("mental_resist", player_to_inspect->GetMentalResistance());
  9544. packet->setDataByName("mental_resist_base", player_to_inspect->GetMentalResistanceBase());
  9545. packet->setDataByName("mental_resist_percentage", 0);
  9546. packet->setDataByName("divine_resist", player_to_inspect->GetDivineResistance());
  9547. packet->setDataByName("divine_resist_base", player_to_inspect->GetDivineResistanceBase());
  9548. packet->setDataByName("divine_resist_percentage", 0);
  9549. packet->setDataByName("disease_resist", player_to_inspect->GetDiseaseResistance());
  9550. packet->setDataByName("disease_resist_base", player_to_inspect->GetDiseaseResistanceBase());
  9551. packet->setDataByName("disease_resist_percentage", 0);
  9552. packet->setDataByName("poison_resist", player_to_inspect->GetPoisonResistance());
  9553. packet->setDataByName("poison_resist_base", player_to_inspect->GetPoisonResistanceBase());
  9554. packet->setDataByName("poison_resist_percentage", 0);
  9555. packet->setArrayLengthByName("num_chars", 0x01FF);
  9556. string biography = player_to_inspect->GetBiography();
  9557. for (size_t i = 0; i < biography.length(); i++)
  9558. packet->setArrayDataByName("biography_char", biography[i], i);
  9559. if (GetVersion() <= 373) {
  9560. for (int32 s = 0; s < 20; s++) {
  9561. int32 slot = s;
  9562. char item_slot_name[64], item_slot_name_appearance[64];
  9563. _snprintf(item_slot_name, 64, "slot_%u", slot);
  9564. Item* pw = player_to_inspect->GetEquipmentList()->GetItem(GetPlayer()->ConvertSlotFromClient(s, GetVersion()));
  9565. packet->setItemByName(item_slot_name, pw, this->GetPlayer(), 0, 7, true, true, true);
  9566. }
  9567. }
  9568. else if (GetVersion() <= 561) {
  9569. for (int32 s = 0; s < 22; s++) {
  9570. int32 slot = s;
  9571. char item_slot_name[64], item_slot_name_appearance[64];
  9572. _snprintf(item_slot_name, 64, "slot_%u", slot);
  9573. Item* pw = player_to_inspect->GetEquipmentList()->GetItem(GetPlayer()->ConvertSlotFromClient(s, GetVersion()));
  9574. packet->setItemByName(item_slot_name, pw, this->GetPlayer(), 0, 5, true, true);
  9575. }
  9576. }
  9577. else {
  9578. for (int32 s = 0; s < NUM_SLOTS; s++) {
  9579. int32 slot = s * 2;
  9580. char item_slot_name[64], item_slot_name_appearance[64];
  9581. _snprintf(item_slot_name, 64, "slot_%u", slot);
  9582. int32 slot_appearance = (s * 2) + 1;
  9583. _snprintf(item_slot_name_appearance, 64, "slot_%u", slot_appearance);
  9584. Item* pw = player_to_inspect->GetEquipmentList()->GetItem(GetPlayer()->ConvertSlotFromClient(s, player_to_inspect->GetClient()->GetVersion()));
  9585. packet->setItemByName(item_slot_name, pw, this->GetPlayer(), 0, 13, false, true);
  9586. if (s <= EQ2_FEET_SLOT || s == EQ2_RANGE_SLOT || s == EQ2_CLOAK_SLOT) {
  9587. pw = player_to_inspect->GetAppearanceEquipmentList()->GetItem(s);
  9588. packet->setItemByName(item_slot_name_appearance, pw, this->GetPlayer(), 0, 13, false, true);
  9589. }
  9590. else {
  9591. packet->setItemByName(item_slot_name_appearance, nullptr, this->GetPlayer(), 0, 13, false, true);
  9592. }
  9593. }
  9594. }
  9595. QueuePacket(packet->serialize());
  9596. safe_delete(packet);
  9597. }
  9598. }
  9599. }
  9600. void Client::SetPendingGuildInvite(Guild* guild, Player* invited_by) {
  9601. pending_guild_invite.guild = guild;
  9602. pending_guild_invite.invited_by = invited_by;
  9603. }
  9604. void Client::ShowClaimWindow() {
  9605. PacketStruct* packet = configReader.getStruct("WS_PromoFlagsDetails", GetVersion());
  9606. if (packet) {
  9607. int16 loaded = database.CountCharClaimItems(GetCharacterID());
  9608. vector<ClaimItems> claim = database.LoadCharacterClaimItems(GetCharacterID());
  9609. int32 account_age = database.GetAccountAge(GetAccountID());
  9610. //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.
  9611. if (loaded == 0 || claim.empty()) {
  9612. Message(CHANNEL_COLOR_RED, "You have nothing to claim.");
  9613. return;
  9614. }
  9615. packet->setArrayLengthByName("num_claim_items", loaded);
  9616. int j = 0; //use this to track skipped vet items.
  9617. for (int i = 0; i < claim.size(); i++)
  9618. {
  9619. if (j == claim.size()) {
  9620. Message(CHANNEL_COLOR_RED, "You have nothing to claim.");
  9621. return;
  9622. }
  9623. Item* item = master_item_list.GetItem(claim[i].item_id);
  9624. int16 claimed = 0;
  9625. if (claim[i].curr_claim < claim[i].max_claim) {
  9626. claimed = claim[i].max_claim - claim[i].curr_claim;
  9627. }
  9628. else {
  9629. claimed = 0;
  9630. }
  9631. //dont display vet rewards until they reach the age required
  9632. if (account_age < claim[i].vet_reward_time) {
  9633. j++;
  9634. continue;
  9635. }
  9636. packet->setArrayDataByName("id", i, i);
  9637. packet->setArrayDataByName("not_yet_claimed", 1, i);
  9638. packet->setArrayDataByName("num_remaining", claim[i].curr_claim, i);
  9639. packet->setArrayDataByName("one_per_character", claim[i].one_per_char, i);
  9640. packet->setArrayDataByName("claimed_on_this_char", 0, i);
  9641. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  9642. packet->setArrayDataByName("text", "If you ever see this text, let a developer know!", i); //I've not seen this!
  9643. //packet->setArrayDataByName("category", "Scott's Shit", i); //devn00b: not using so commenting out, leaving in case we ever do implement categories.
  9644. packet->setArrayDataByName("icon", item->GetIcon(GetVersion()), i);
  9645. packet->setArrayDataByName("item_id", item->details.item_id, i);
  9646. j++;
  9647. }
  9648. }
  9649. packet->setDataByName("unknown3", 1);
  9650. QueuePacket(packet->serialize());
  9651. safe_delete(packet);
  9652. }
  9653. void Client::ShowGuildSearchWindow() {
  9654. PacketStruct* packet = configReader.getStruct("WS_GuildRecruiting", GetVersion());
  9655. if (packet) {
  9656. MutexMap<int32, Guild*>* guilds = guild_list.GetGuilds();
  9657. MutexMap<int32, Guild*>::iterator itr = guilds->begin();
  9658. packet->setArrayLengthByName("num_guilds", guilds->size());
  9659. int32 i = 0;
  9660. while (itr.Next()) {
  9661. Guild* guild = itr.second;
  9662. packet->setArrayDataByName("guild_id", guild->GetID(), i);
  9663. packet->setArrayDataByName("guild_name", guild->GetName(), i);
  9664. packet->setArrayDataByName("recruiting_short_description", guild->GetRecruitingShortDesc().c_str(), i);
  9665. packet->setArrayDataByName("descriptive_tag1", guild->GetRecruitingDescTag(0), i);
  9666. packet->setArrayDataByName("descriptive_tag2", guild->GetRecruitingDescTag(1), i);
  9667. packet->setArrayDataByName("descriptive_tag3", guild->GetRecruitingDescTag(2), i);
  9668. packet->setArrayDataByName("descriptive_tag4", guild->GetRecruitingDescTag(3), i);
  9669. packet->setArrayDataByName("playstyle", guild->GetRecruitingPlayStyle(), i);
  9670. packet->setArrayDataByName("looking_for", guild->GetRecruitingLookingForPacketValue(), i); //tradeskillers, fighters, new
  9671. packet->setArrayDataByName("unknown7", 0x02, i);
  9672. packet->setArrayDataByName("min_level", guild->GetRecruitingMinLevel(), i);
  9673. i++;
  9674. }
  9675. QueuePacket(packet->serialize());
  9676. safe_delete(packet);
  9677. }
  9678. }
  9679. void Client::ShowDressingRoom(Item* item, sint32 crc) {
  9680. PacketStruct* packet;
  9681. vector<int8>* slot_data;
  9682. vector<int8>::iterator itr;
  9683. int32 slots = 0;
  9684. assert(item);
  9685. if (!(packet = configReader.getStruct("WS_DressingRoom", GetVersion()))) {
  9686. return;
  9687. }
  9688. slot_data = &item->slot_data;
  9689. for (itr = slot_data->begin(); itr != slot_data->end(); itr++) {
  9690. if (version >= 1188)
  9691. slots = *itr;
  9692. else
  9693. slots += (int8)pow(2.0, *itr);
  9694. }
  9695. packet->setDataByName("slot", slots);
  9696. packet->setDataByName("appearance_id", item->generic_info.appearance_id);
  9697. if (slots == 2) {
  9698. packet->setDataByName("rgb", item->generic_info.appearance_red, 2);
  9699. packet->setDataByName("rgb", item->generic_info.appearance_blue, 0);
  9700. }
  9701. else {
  9702. packet->setDataByName("rgb", item->generic_info.appearance_red, 0);
  9703. packet->setDataByName("rgb", item->generic_info.appearance_blue, 2);
  9704. }
  9705. packet->setDataByName("rgb", item->generic_info.appearance_green, 1);
  9706. if (slots == 4) {
  9707. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 2);
  9708. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  9709. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 0);
  9710. }
  9711. else if (slots == 7) {
  9712. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 1);
  9713. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 0);
  9714. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  9715. }
  9716. else {
  9717. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 0);
  9718. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  9719. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  9720. }
  9721. packet->setDataByName("icon", item->GetIcon(GetVersion()));
  9722. packet->setDataByName("item_id", item->details.item_id);
  9723. packet->setDataByName("item_crc", crc);
  9724. packet->setDataByName("unknown2", 0xFFFFFFFF);
  9725. packet->setDataByName("unknown4", 0xFFFFFFFF);
  9726. packet->setDataByName("unknown5", 0xFF, 9);
  9727. packet->setDataByName("unknown5", 0xFF, 10);
  9728. QueuePacket(packet->serialize());
  9729. safe_delete(packet);
  9730. }
  9731. void Client::SendCollectionList() {
  9732. map<int32, Collection*>* collections = player->GetCollectionList()->GetCollections();
  9733. map<int32, Collection*>::iterator itr;
  9734. vector<struct CollectionItem*>* collection_items;
  9735. Collection* collection;
  9736. struct CollectionItem* collection_item;
  9737. PacketStruct* packet = 0;
  9738. int16 i = 0, j;
  9739. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version)))
  9740. return;
  9741. packet->setArrayLengthByName("num_collections", collections->size());
  9742. for (itr = collections->begin(); itr != collections->end(); itr++) {
  9743. collection = itr->second;
  9744. collection_items = collection->GetCollectionItems();
  9745. packet->setArrayDataByName("unknown", 1, i);
  9746. packet->setArrayDataByName("collection_name", collection->GetName(), i);
  9747. packet->setArrayDataByName("collection_category", collection->GetCategory(), i);
  9748. packet->setArrayDataByName("completed", collection->GetCompleted(), i);
  9749. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  9750. packet->setArrayDataByName("level", collection->GetLevel(), i);
  9751. packet->setArrayDataByName("ready_to_turn_in", collection->GetIsReadyToTurnIn(), i);
  9752. packet->setSubArrayLengthByName("num_items", collection_items->size(), i);
  9753. for (j = 0; j < collection_items->size(); j++) {
  9754. collection_item = collection_items->at(j);
  9755. Item* item = master_item_list.GetItem(collection_item->item);
  9756. if (item) {
  9757. packet->setSubArrayDataByName("item_icon", item->GetIcon(GetVersion()), i, j);
  9758. if (version < 955)
  9759. packet->setSubArrayDataByName("item_name", item->name.c_str(), i, j);
  9760. else
  9761. packet->setSubArrayDataByName("item_id", item->details.item_id, i, j);
  9762. }
  9763. packet->setSubArrayDataByName("item_flag", collection_item->found, i, j);
  9764. }
  9765. i++;
  9766. }
  9767. packet->setDataByName("new_collection_flag", 1);
  9768. QueuePacket(packet->serialize());
  9769. safe_delete(packet);
  9770. }
  9771. bool Client::SendCollectionsForItem(Item* item) {
  9772. map<int32, Collection*> collections_to_send;
  9773. map<int32, Collection*>* collections;
  9774. map<int32, Collection*>::iterator itr;
  9775. vector<struct CollectionItem*>* collection_items;
  9776. Collection* collection;
  9777. struct CollectionItem* collection_item;
  9778. PacketStruct* packet;
  9779. int16 i;
  9780. assert(item);
  9781. /* get any collections required by this item that the player already has */
  9782. collections = player->GetCollectionList()->GetCollections();
  9783. for (itr = collections->begin(); itr != collections->end(); itr++) {
  9784. collection = itr->second;
  9785. if (!collection->GetCompleted() && !collection->GetIsReadyToTurnIn() && collection->NeedsItem(item)) {
  9786. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from player list %u\n", collection->GetID());
  9787. collections_to_send[collection->GetID()] = collection;
  9788. }
  9789. }
  9790. /* get any collections required by this item that the player does not have and send it to the client */
  9791. collections = master_collection_list.GetCollections();
  9792. for (itr = collections->begin(); itr != collections->end(); itr++) {
  9793. collection = itr->second;
  9794. if (collection->NeedsItem(item) && !player->GetCollectionList()->GetCollection(collection->GetID())) {
  9795. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version))) {
  9796. return false;
  9797. }
  9798. packet->setArrayLengthByName("num_collections", 1);
  9799. packet->setArrayDataByName("unknown", 1, 0);
  9800. packet->setArrayDataByName("collection_name", collection->GetName(), 0);
  9801. packet->setArrayDataByName("collection_category", collection->GetCategory(), 0);
  9802. packet->setArrayDataByName("completed", 0, 0);
  9803. packet->setArrayDataByName("collection_id", collection->GetID(), 0);
  9804. packet->setArrayDataByName("level", collection->GetLevel(), 0);
  9805. packet->setArrayDataByName("ready_to_turn_in", 0, 0);
  9806. packet->setArrayDataByName("unknown3", 0x28, 0);
  9807. collection_items = collection->GetCollectionItems();
  9808. packet->setSubArrayLengthByName("num_items", collection_items->size(), 0);
  9809. for (i = 0; i < collection_items->size(); i++) {
  9810. collection_item = collection_items->at(i);
  9811. Item* item2 = master_item_list.GetItem(collection_item->item);
  9812. if (item2) {
  9813. packet->setSubArrayDataByName("item_icon", item2->GetIcon(GetVersion()), 0, i);
  9814. if (version < 955)
  9815. packet->setSubArrayDataByName("item_name", item2->name.c_str(), 0, i);
  9816. else
  9817. packet->setSubArrayDataByName("item_id", item2->details.item_id, 0, i);
  9818. packet->setSubArrayDataByName("item_flag", collection_item->found, 0, i);
  9819. }
  9820. }
  9821. packet->setDataByName("new_collection_flag", 0);
  9822. QueuePacket(packet->serialize());
  9823. safe_delete(packet);
  9824. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from master list %u\n", collection->GetID());
  9825. collections_to_send[collection->GetID()] = collection;
  9826. }
  9827. }
  9828. /* send the client a list of collections that should be filtered for this item */
  9829. if (collections_to_send.size() > 0) {
  9830. if (!(packet = configReader.getStruct("WS_CollectionFilter", version))) {
  9831. return false;
  9832. }
  9833. i = 0;
  9834. packet->setArrayLengthByName("num_filters", collections_to_send.size());
  9835. for (itr = collections_to_send.begin(); itr != collections_to_send.end(); itr++) {
  9836. collection = itr->second;
  9837. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  9838. packet->setArrayDataByName("collection_item_num", collection->GetCollectionItemByItemID(item->details.item_id)->index, i);
  9839. i++;
  9840. }
  9841. packet->setDataByName("item_icon", item->GetIcon(GetVersion()));
  9842. packet->setDataByName("item_name", item->name.c_str());
  9843. packet->setDataByName("item_id", item->details.item_id);
  9844. packet->setDataByName("unknown3", player->GetCollectionList()->Size());
  9845. QueuePacket(packet->serialize());
  9846. safe_delete(packet);
  9847. }
  9848. return collections_to_send.size() > 0;
  9849. }
  9850. void Client::HandleCollectionAddItem(int32 collection_id, Item* item) {
  9851. Collection* collection;
  9852. struct CollectionItem* collection_item;
  9853. PacketStruct* packet;
  9854. char tmp[200] = { 0 };
  9855. assert(item);
  9856. /* first try to get the collection from the player's collection list. if it's not found, get it from the master list */
  9857. if ((collection = player->GetCollectionList()->GetCollection(collection_id))) {
  9858. /* get the item struct that represents the item for this collection */
  9859. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  9860. SendCollectionList();
  9861. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  9862. return;
  9863. }
  9864. /* sanity check */
  9865. if (collection_item->found) {
  9866. SendCollectionList();
  9867. 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());
  9868. return;
  9869. }
  9870. }
  9871. else if ((collection = master_collection_list.GetCollection(collection_id))) {
  9872. collection = new Collection(collection);
  9873. /* get the item struct that represents the item for this collection */
  9874. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  9875. SendCollectionList();
  9876. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  9877. safe_delete(collection);
  9878. return;
  9879. }
  9880. /* add the new collection to the player's collection list */
  9881. if (!player->GetCollectionList()->AddCollection(collection)) {
  9882. SendCollectionList();
  9883. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Player '%s' already has collection '%s'", player->GetName(), collection->GetName());
  9884. safe_delete(collection);
  9885. return;
  9886. }
  9887. }
  9888. else {
  9889. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find collection with id %u", collection_id);
  9890. return;
  9891. }
  9892. collection_item->found = 1;
  9893. collection->SetSaveNeeded(true);
  9894. if (!(packet = configReader.getStruct("WS_CollectionItem", version))) {
  9895. SendCollectionList();
  9896. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find struct 'WS_CollectionItem'");
  9897. return;
  9898. }
  9899. packet->setDataByName("collection_id", collection_id);
  9900. packet->setDataByName("collection_item_num", collection_item->index);
  9901. packet->setDataByName("add", 1);
  9902. QueuePacket(packet->serialize());
  9903. Item* item2 = master_item_list.GetItem(collection_item->item);
  9904. if (item2) {
  9905. Message(CHANNEL_COLOR_YELLOW, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  9906. sprintf(tmp, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  9907. SendPopupMessage(5, tmp, "quest_item", 3.5, 0x64, 0xFF, 0xFF);
  9908. }
  9909. safe_delete(packet);
  9910. RemoveItem(item, 1);
  9911. SendCollectionList();
  9912. }
  9913. void Client::DisplayCollectionComplete(Collection* collection) {
  9914. vector<struct CollectionRewardItem*>* reward_items;
  9915. vector<struct CollectionRewardItem*>* selectable_reward_items;
  9916. struct CollectionRewardItem* reward_item;
  9917. PacketStruct* packet;
  9918. int32 i;
  9919. assert(collection);
  9920. reward_items = collection->GetRewardItems();
  9921. selectable_reward_items = collection->GetSelectableRewardItems();
  9922. if (GetVersion() <= 561) {
  9923. int32 source_id = collection->GetID();
  9924. PacketStruct* packet2 = configReader.getStruct("WS_QuestRewardPackMsg", GetVersion());
  9925. if (packet2) {
  9926. packet2->setSubstructDataByName("reward_data", "unknown1", 255);
  9927. packet2->setSubstructDataByName("reward_data", "reward", "Quest Reward!");
  9928. packet2->setSubstructDataByName("reward_data", "max_coin", collection->GetRewardCoin());
  9929. packet2->setSubstructDataByName("reward_data", "exp_bonus", collection->GetRewardXP());
  9930. if (reward_items) {
  9931. int32 item_count = reward_items->size();
  9932. packet2->setSubstructArrayLengthByName("reward_data", "num_rewards", item_count);
  9933. i = 0;
  9934. if (reward_items) {
  9935. for (i = 0; i < reward_items->size(); i++) {
  9936. Item* item = reward_items->at(i)->item;
  9937. if (item) {
  9938. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  9939. packet2->setItemArrayDataByName("item", item, player, i, 0, GetClientItemPacketOffset());
  9940. }
  9941. }
  9942. }
  9943. }
  9944. if (selectable_reward_items) {
  9945. packet2->setSubstructArrayLengthByName("reward_data", "num_select_rewards", selectable_reward_items->size());
  9946. for (i = 0; i < selectable_reward_items->size(); i++) {
  9947. Item* item = selectable_reward_items->at(i)->item;
  9948. if (item) {
  9949. packet2->setArrayDataByName("select_reward_id", item->details.item_id, i);
  9950. packet2->setItemArrayDataByName("select_item", item, player, i, 0, GetClientItemPacketOffset());
  9951. }
  9952. }
  9953. }
  9954. }
  9955. EQ2Packet* app = packet2->serialize();
  9956. QueuePacket(app);
  9957. safe_delete(packet2);
  9958. return;
  9959. }
  9960. if (!(packet = configReader.getStruct("WS_QuestComplete", version))) {
  9961. return;
  9962. }
  9963. packet->setDataByName("title", "Quest Reward!");
  9964. packet->setDataByName("name", collection->GetName());
  9965. packet->setDataByName("description", collection->GetCategory());
  9966. packet->setDataByName("level", collection->GetLevel());
  9967. packet->setDataByName("max_coin", collection->GetRewardCoin());
  9968. packet->setDataByName("min_coin", collection->GetRewardCoin());
  9969. //packet->setDataByName("status_points", quest->GetStatusPoints());
  9970. packet->setArrayLengthByName("num_rewards", reward_items->size());
  9971. for (i = 0; i < reward_items->size(); i++) {
  9972. reward_item = reward_items->at(i);
  9973. if (!reward_item->item)
  9974. {
  9975. LogWrite(DATABASE__ERROR, 0, "Database", "DisplayCollectionComplete Collection %s (%u) num_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  9976. Message(CHANNEL_COLOR_RED, "DisplayCollectionComplete Collection %s (%u) num_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  9977. continue;
  9978. }
  9979. packet->setArrayDataByName("reward_id", reward_item->item->details.item_id, i);
  9980. if (version < 860)
  9981. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, GetClientItemPacketOffset());
  9982. else if (version < 1193)
  9983. packet->setItemArrayDataByName("item", reward_item->item, player, i);
  9984. else
  9985. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, 2);
  9986. }
  9987. packet->setArrayLengthByName("num_select_rewards", selectable_reward_items->size());
  9988. for (i = 0; i < selectable_reward_items->size(); i++) {
  9989. reward_item = selectable_reward_items->at(i);
  9990. if (!reward_item->item)
  9991. {
  9992. LogWrite(DATABASE__ERROR, 0, "Database", "DisplayCollectionComplete Collection %s (%u) num_select_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  9993. Message(CHANNEL_COLOR_RED, "DisplayCollectionComplete Collection %s (%u) num_select_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  9994. continue;
  9995. }
  9996. packet->setArrayDataByName("select_reward_id", reward_item->item->details.item_id, i);
  9997. if (version < 860)
  9998. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, GetClientItemPacketOffset());
  9999. else if (version < 1193)
  10000. packet->setItemArrayDataByName("select_item", reward_item->item, player, i);
  10001. else
  10002. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, 2);
  10003. }
  10004. QueuePacket(packet->serialize());
  10005. safe_delete(packet);
  10006. }
  10007. void Client::HandInCollections() {
  10008. map<int32, Collection*>* collections;
  10009. map<int32, Collection*>::iterator itr;
  10010. Collection* collection;
  10011. /* only show 1 collection reward dialog at a time */
  10012. if (player->GetPendingCollectionReward()) {
  10013. return;
  10014. }
  10015. collections = player->GetCollectionList()->GetCollections();
  10016. /* 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
  10017. for this collection, this function gets called again and the process repeats until there are no more collections to hand in */
  10018. for (itr = collections->begin(); itr != collections->end(); itr++) {
  10019. collection = itr->second;
  10020. if (collection->GetIsReadyToTurnIn()) {
  10021. player->SetPendingCollectionReward(collection);
  10022. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  10023. QuestRewardData* data = new QuestRewardData;
  10024. data->quest_id = 0;
  10025. data->is_temporary = false;
  10026. data->description = std::string("");
  10027. data->is_collection = true;
  10028. data->has_displayed = false;
  10029. data->tmp_coin = 0;
  10030. data->tmp_status = 0;
  10031. data->db_saved = false;
  10032. data->db_index = 0;
  10033. quest_pending_reward.push_back(data);
  10034. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  10035. quest_updates = true;
  10036. break;
  10037. }
  10038. }
  10039. if (quest_updates) {
  10040. SaveQuestRewardData(true);
  10041. }
  10042. }
  10043. void Client::AcceptCollectionRewards(Collection* collection, int32 selectable_item_id) {
  10044. vector<struct CollectionRewardItem*>* reward_items;
  10045. vector<struct CollectionRewardItem*>::iterator itr;
  10046. struct CollectionRewardItem* reward_item;
  10047. int16 num_slots_needed;
  10048. int16 num_slots;
  10049. assert(collection);
  10050. reward_items = collection->GetRewardItems();
  10051. num_slots_needed = (int16)reward_items->size();
  10052. if (selectable_item_id > 0)
  10053. num_slots_needed++;
  10054. num_slots = player->GetPlayerItemList()->GetNumberOfFreeSlots();
  10055. if (num_slots < num_slots_needed) {
  10056. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots. Free up some slots and try again");
  10057. DisplayCollectionComplete(collection);
  10058. return;
  10059. }
  10060. /* add manditory items */
  10061. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  10062. reward_item = *itr;
  10063. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  10064. }
  10065. /* find and add the selectable item if there's one */
  10066. if (selectable_item_id > 0) {
  10067. reward_items = collection->GetSelectableRewardItems();
  10068. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  10069. reward_item = *itr;
  10070. if (reward_item->item->details.item_id == selectable_item_id) {
  10071. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  10072. break;
  10073. }
  10074. }
  10075. }
  10076. if (collection->GetRewardXP() > 0) {
  10077. player->AddXP((int32)collection->GetRewardXP());
  10078. }
  10079. if (collection->GetRewardCoin() > 0) {
  10080. player->AddCoins(collection->GetRewardCoin());
  10081. Message(CHANNEL_COLOR_YELLOW, "You receive %s", GetCoinMessage(collection->GetRewardCoin()).c_str());
  10082. }
  10083. collection->SetCompleted(true);
  10084. //update achievements for completeing collection here
  10085. collection->SetSaveNeeded(true);
  10086. SendCollectionList();
  10087. /* reset the pending collection reward and check for my collections that the player needs to hand in */
  10088. player->SetPendingCollectionReward(0);
  10089. RemoveQueuedQuestReward();
  10090. GetPlayer()->SetActiveReward(false);
  10091. HandInCollections();
  10092. GetPlayer()->GetZone()->SendSubSpawnUpdates(SUBSPAWN_TYPES::COLLECTOR);
  10093. }
  10094. void Client::SendRecipeList() {
  10095. if (GetRecipeListSent()) {
  10096. return;
  10097. }
  10098. PacketStruct* packet = 0;
  10099. map<int32, Recipe*>* recipes = player->GetRecipeList()->GetRecipes();
  10100. map<int32, Recipe*>::iterator itr;
  10101. int16 i = 0;
  10102. Recipe* recipe;
  10103. if (version <= 561) {
  10104. PacketStruct* packet = 0;
  10105. if (!(packet = configReader.getStruct("WS_UpdateRecipeBook", GetVersion()))) {
  10106. return;
  10107. }
  10108. packet->setArrayLengthByName("recipe_count", recipes->size());
  10109. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  10110. recipe = itr->second;
  10111. int32 recipe_id = recipe->GetID();
  10112. packet->setArrayDataByName("recipe_id", recipe_id, i);
  10113. packet->setArrayDataByName("recipe_data_crc", GetRecipeCRC(recipe), i);
  10114. packet->setArrayDataByName("unknown", 0x7005BE3, i); //0x7005BE3
  10115. i++;
  10116. }
  10117. EQ2Packet* ret = packet->serializeCountPacket(GetVersion(), 0, nullptr, nullptr);
  10118. QueuePacket(ret);
  10119. safe_delete(packet);
  10120. SetRecipeListSent(true);
  10121. return;
  10122. }
  10123. else if (!(packet = configReader.getStruct("WS_RecipeList", version))) {
  10124. return;
  10125. }
  10126. int8 level = player->GetTSLevel();
  10127. int index = 0;
  10128. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  10129. recipe = itr->second;
  10130. auto res = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  10131. if (res != devices.end())
  10132. index = res - devices.begin();
  10133. else
  10134. devices.push_back(recipe->GetDevice());
  10135. }
  10136. packet->setDataByName("command_type", 0);
  10137. packet->setArrayLengthByName("num_recipes", recipes->size());
  10138. int stringsize = 0;
  10139. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  10140. recipe = itr->second;
  10141. int32 myid = recipe->GetID();
  10142. int8 rlevel = recipe->GetLevel();
  10143. int8 even = level - level * .05 + .5;
  10144. int8 easymin = level - level * .25 + .5;
  10145. int8 veasymin = level - level * .35 + .5;
  10146. if (rlevel > level)
  10147. packet->setArrayDataByName("tier", 4, i);
  10148. else if ((rlevel <= level) & (rlevel >= even))
  10149. packet->setArrayDataByName("tier", 3, i);
  10150. else if ((rlevel <= even) & (rlevel >= easymin))
  10151. packet->setArrayDataByName("tier", 2, i);
  10152. else if ((rlevel <= easymin) & (rlevel >= veasymin))
  10153. packet->setArrayDataByName("tier", 1, i);
  10154. else if ((rlevel <= veasymin) & (rlevel >= 0))
  10155. packet->setArrayDataByName("tier", 0, i);
  10156. if (rlevel == 2)
  10157. int xxx = 1;
  10158. packet->setArrayDataByName("recipe_id", myid, i);
  10159. packet->setArrayDataByName("level", recipe->GetLevel(), i);
  10160. packet->setArrayDataByName("unknown1", recipe->GetLevel(), i);
  10161. packet->setArrayDataByName("icon", recipe->GetIcon(), i);
  10162. packet->setArrayDataByName("classes", recipe->GetClasses(), i);
  10163. packet->setArrayDataByName("technique", recipe->GetTechnique(), i);
  10164. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), i);
  10165. auto recipe_device = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  10166. if (recipe_device != devices.end())
  10167. packet->setArrayDataByName("device_type", recipe_device - devices.begin(), i);
  10168. else
  10169. {//TODO error should never get here
  10170. }
  10171. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), i);
  10172. packet->setArrayDataByName("recipe_name", recipe->GetName(), i);
  10173. packet->setArrayDataByName("recipe_book", recipe->GetBook(), i);
  10174. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), i);
  10175. i++;
  10176. }
  10177. //packet->PrintPacket();
  10178. EQ2Packet* pack = packet->serialize();
  10179. QueuePacket(pack);
  10180. safe_delete(packet);
  10181. SetRecipeListSent(true);
  10182. }
  10183. void Client::ShowRecipeBook() {
  10184. PacketStruct* packet = 0;
  10185. Spawn* target = 0;
  10186. int index = 0;
  10187. if (!(target = player->GetTarget())) {
  10188. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have a tradeskill device targeted");
  10189. return;
  10190. }
  10191. if (!target->IsObject() || !((Object*)target)->GetDeviceID()) {
  10192. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have a tradeskill device targeted");
  10193. return;
  10194. }
  10195. if (!(packet = configReader.getStruct("WS_ShowRecipeBook", version))) {
  10196. return;
  10197. }
  10198. packet->setDataByName("device", target->GetName());
  10199. packet->setDataByName("unknown1", 1);
  10200. auto res = std::find(devices.begin(), devices.end(), target->GetName());
  10201. if (res != devices.end()) {
  10202. index = res - devices.begin();
  10203. int32 deviceID = 0;
  10204. deviceID |= 1UL << index;
  10205. //LogWrite(TRADESKILL__ERROR, 0, "Tradeskills", "GetDeviceID() = %u, deviceID = %u", ((Object*)target)->GetDeviceID(), deviceID);
  10206. packet->setDataByName("unknown2", devices.size());
  10207. packet->setDataByName("unknown3", deviceID);
  10208. }
  10209. else
  10210. packet->setDataByName("unknown2", devices.size());
  10211. QueuePacket(packet->serialize());
  10212. safe_delete(packet);
  10213. }
  10214. void Client::SendTitleUpdate() {
  10215. // must call release read lock before leaving function on GetPlayerTitles
  10216. vector<Title*>* titles = player->GetPlayerTitles()->GetAllTitles();
  10217. vector<Title*>::iterator itr;
  10218. Title* title;
  10219. sint32 i = 0;
  10220. sint32 prefix_index = database.GetCharPrefixIndex(GetCharacterID(), player);
  10221. sint32 suffix_index = database.GetCharSuffixIndex(GetCharacterID(), player);
  10222. PacketStruct* packet = configReader.getStruct("WS_TitleUpdate", GetVersion());
  10223. if (packet) {
  10224. packet->setArrayLengthByName("num_titles", titles->size());
  10225. for (itr = titles->begin(); itr != titles->end(); itr++) {
  10226. title = *itr;
  10227. packet->setArrayDataByName("title", title->GetName(), i);
  10228. packet->setArrayDataByName("prefix", title->GetPrefix(), i);
  10229. i++;
  10230. }
  10231. packet->setDataByName("current_prefix", prefix_index);
  10232. packet->setDataByName("current_suffix", suffix_index);
  10233. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  10234. #if EQDEBUG >= 9
  10235. packet->PrintPacket();
  10236. #endif
  10237. QueuePacket(packet->serialize());
  10238. safe_delete(packet);
  10239. SendUpdateTitles(prefix_index, suffix_index);
  10240. }
  10241. player->GetPlayerTitles()->ReleaseReadLock();
  10242. }
  10243. void Client::SendUpdateTitles(sint32 prefix, sint32 suffix) {
  10244. Title* suffix_title = 0;
  10245. Title* prefix_title = 0;
  10246. if (suffix != -1) {
  10247. suffix_title = player->GetPlayerTitles()->GetTitle(suffix);
  10248. if (suffix_title)
  10249. strcpy(player->appearance.suffix_title, suffix_title->GetName());
  10250. }
  10251. else
  10252. memset(player->appearance.suffix_title, 0, strlen(player->appearance.suffix_title));
  10253. if (prefix != -1) {
  10254. prefix_title = player->GetPlayerTitles()->GetTitle(prefix);
  10255. if (prefix_title)
  10256. strcpy(player->appearance.prefix_title, prefix_title->GetName());
  10257. }
  10258. else
  10259. memset(player->appearance.prefix_title, 0, strlen(player->appearance.prefix_title));
  10260. current_zone->SendUpdateTitles(this, suffix_title, prefix_title);
  10261. }
  10262. void Client::SendLanguagesUpdate(int32 id, bool setlang) {
  10263. list<Language*>* languages = player->GetPlayerLanguages()->GetAllLanguages();
  10264. list<Language*>::iterator itr;
  10265. Language* language;
  10266. int32 i = 0;
  10267. if (setlang == 1) {
  10268. GetPlayer()->SetCurrentLanguage(id);
  10269. }
  10270. PacketStruct* packet = configReader.getStruct("WS_Languages", GetVersion());
  10271. if (packet) {
  10272. packet->setArrayLengthByName("num_languages", languages->size());
  10273. for (itr = languages->begin(); itr != languages->end(); itr++) {
  10274. language = *itr;
  10275. packet->setArrayDataByName("language_id", language->GetID(), i);
  10276. i++;
  10277. }
  10278. packet->setDataByName("current_language", id);
  10279. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  10280. #if EQDEBUG >= 9
  10281. packet->PrintPacket();
  10282. #endif
  10283. QueuePacket(packet->serialize());
  10284. safe_delete(packet);
  10285. }
  10286. }
  10287. void Client::SendPetOptionsWindow(const char* pet_name, int8 type) {
  10288. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  10289. if (packet) {
  10290. if (pet_name)
  10291. packet->setDataByName("pet_name", pet_name);
  10292. if (player->GetInfoStruct()->get_pet_behavior() & 1)
  10293. packet->setDataByName("protect_master", 1);
  10294. if (player->GetInfoStruct()->get_pet_behavior() & 2)
  10295. packet->setDataByName("protect_self", 1);
  10296. if (player->GetInfoStruct()->get_pet_movement() == 2)
  10297. packet->setDataByName("stay_follow_toggle", 1);
  10298. packet->setDataByName("pet_type", type);
  10299. QueuePacket(packet->serialize());
  10300. }
  10301. safe_delete(packet);
  10302. }
  10303. bool Client::IsCrafting() {
  10304. return current_zone->GetTradeskillMgr()->IsClientCrafting(this);
  10305. }
  10306. void Client::SendBiography() {
  10307. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  10308. if (packet) {
  10309. char biography[512];
  10310. if (player->GetInfoStruct()->get_biography().size() < 1)
  10311. {
  10312. safe_delete(packet);
  10313. return;
  10314. }
  10315. else
  10316. {
  10317. int16 size = player->GetInfoStruct()->get_biography().size();
  10318. if (size > 511)
  10319. size = 511;
  10320. strncpy(biography, player->GetInfoStruct()->get_biography().c_str(), player->GetInfoStruct()->get_biography().size());
  10321. biography[player->GetInfoStruct()->get_biography().size()] = '\0';
  10322. }
  10323. packet->setDataByName("biography", biography);
  10324. QueuePacket(packet->serialize());
  10325. }
  10326. safe_delete(packet);
  10327. }
  10328. PendingResurrection* Client::GetCurrentRez() {
  10329. return &current_rez;
  10330. }
  10331. Mutex* Client::GetResurrectMutex() {
  10332. return &m_resurrect;
  10333. }
  10334. void Client::SendResurrectionWindow() {
  10335. Spawn* caster = current_rez.caster;
  10336. if (!caster || !player)
  10337. return;
  10338. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  10339. if (!packet)
  10340. return;
  10341. char* tmp = new char[512];
  10342. sprintf(tmp, "%s would like to cast '%s' on you. Do you accept?", caster->GetName(), current_rez.spell_name.c_str());
  10343. packet->setMediumStringByName("text", tmp);
  10344. packet->setMediumStringByName("accept_text", "Yes");
  10345. packet->setMediumStringByName("cancel_text", "No");
  10346. sprintf(tmp, "accept_resurrection %u", player->GetID());
  10347. packet->setMediumStringByName("accept_command", tmp);
  10348. sprintf(tmp, "decline_resurrection %u", player->GetID());
  10349. packet->setMediumStringByName("cancel_command", tmp);
  10350. packet->setDataByName("time", current_rez.expire_timer->GetRemainingTime() / 1000);
  10351. QueuePacket(packet->serialize());
  10352. safe_delete(packet);
  10353. safe_delete_array(tmp);
  10354. }
  10355. void Client::AcceptResurrection() {
  10356. Spawn* caster = current_rez.caster;
  10357. if (!player || !caster)
  10358. return;
  10359. if (player->Alive())
  10360. return;
  10361. if ((caster->GetZone() != player->GetZone()) || (current_rez.range > 0 && player->GetDistance(caster) > current_rez.range)) {
  10362. SimpleMessage(CHANNEL_COLOR_YELLOW, "The caster must be nearby to complete the spell.");
  10363. SendResurrectionWindow();
  10364. return;
  10365. }
  10366. player->GetZone()->ResurrectSpawn(player, this);
  10367. current_rez.should_delete = true;
  10368. }
  10369. void Client::SetPendingLastName(string last_name) {
  10370. pending_last_name = new string;
  10371. pending_last_name->assign(last_name);
  10372. }
  10373. string* Client::GetPendingLastName() {
  10374. return pending_last_name;
  10375. }
  10376. void Client::RemovePendingLastName() {
  10377. safe_delete(pending_last_name);
  10378. }
  10379. void Client::SendLastNameConfirmation() {
  10380. if (!pending_last_name)
  10381. return;
  10382. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  10383. if (packet) {
  10384. char* text = new char[128];
  10385. sprintf(text, "Are you sure you want your last name to be \"%s\"?", pending_last_name->c_str());
  10386. packet->setDataByName("text", text);
  10387. packet->setDataByName("accept_text", "Yes");
  10388. packet->setDataByName("accept_command", "confirmedlastname");
  10389. packet->setDataByName("cancel_text", "No");
  10390. packet->setDataByName("max_length", 50);
  10391. packet->setDataByName("unknown4", 1);
  10392. packet->setDataByName("unknown5", 1);
  10393. QueuePacket(packet->serialize());
  10394. safe_delete(packet);
  10395. safe_delete_array(text);
  10396. }
  10397. }
  10398. void Client::AddQuestTimer(int32 quest_id) {
  10399. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  10400. quest_timers.push_back(quest_id);
  10401. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  10402. }
  10403. void Client::RemoveQuestTimer(int32 quest_id) {
  10404. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  10405. vector<int32>::iterator itr;
  10406. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  10407. if ((*itr) == quest_id) {
  10408. quest_timers.erase(itr);
  10409. break;
  10410. }
  10411. }
  10412. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  10413. }
  10414. void Client::SavePlayerImages() {
  10415. LogWrite(CCLIENT__DEBUG, 0, "Client", "Saving %s image for player %s (%u)", (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL ? "paperdoll" : "headshot"), GetPlayer()->GetName(), GetCharacterID());
  10416. // Save the paperdoll image if the server allows it
  10417. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL && rule_manager.GetZoneRule(GetCurrentZoneID(), R_World, SavePaperdollImage)->GetBool())
  10418. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  10419. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_HEAD) {
  10420. // Save the head shot if the server allows it
  10421. if (rule_manager.GetZoneRule(GetCurrentZoneID(), R_World, SaveHeadshotImage)->GetBool())
  10422. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  10423. // Send the head shot to the login server
  10424. if (rule_manager.GetZoneRule(GetCurrentZoneID(), R_World, SendPaperdollImagesToLogin)->GetBool()) {
  10425. int32 size = incoming_paperdoll.current_size_bytes + CHARPICSTRUCT_MINSIZE;
  10426. ServerPacket* packet = new ServerPacket(ServerOP_CharacterPicture, size);
  10427. memset(packet->pBuffer, 0, size);
  10428. CharPictureUpdate_Struct* pic = (CharPictureUpdate_Struct*)packet->pBuffer;
  10429. pic->account_id = GetAccountID();
  10430. pic->char_id = GetCharacterID();
  10431. pic->pic_size = (int16)incoming_paperdoll.current_size_bytes;
  10432. memcpy(pic->pic, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  10433. loginserver.SendPacket(packet);
  10434. safe_delete(packet);
  10435. }
  10436. }
  10437. safe_delete_array(incoming_paperdoll.image_bytes);
  10438. incoming_paperdoll.current_size_bytes = 0;
  10439. }
  10440. void Client::EndAutoMount() {
  10441. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  10442. if (packet) {
  10443. packet->setDataByName("parameter1", 128);
  10444. packet->setDataByName("parameter2", 64);
  10445. packet->setDataByName("value", 1);
  10446. QueuePacket(packet->serialize());
  10447. safe_delete(packet);
  10448. }
  10449. packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  10450. if (packet) {
  10451. packet->setDataByName("parameter3", 4);
  10452. packet->setDataByName("parameter5", 2);
  10453. packet->setDataByName("value", 0);
  10454. QueuePacket(packet->serialize());
  10455. safe_delete(packet);
  10456. }
  10457. packet = configReader.getStruct("WS_ClearForLanding", GetVersion());
  10458. if (packet) {
  10459. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  10460. QueuePacket(packet->serialize());
  10461. safe_delete(packet);
  10462. }
  10463. on_auto_mount = false;
  10464. player->SetMount(((Player*)player)->GetTempMount());
  10465. EQ2_Color mount_color = player->GetTempMountColor();
  10466. EQ2_Color saddle_color = player->GetTempMountSaddleColor();
  10467. player->SetMountColor(&mount_color);
  10468. player->SetMountSaddleColor(&saddle_color);
  10469. player->SetTempMount(0);
  10470. }
  10471. bool Client::EntityCommandPrecheck(Spawn* spawn, const char* command) {
  10472. const char* spawn_script = spawn->GetSpawnScript();
  10473. bool should_use_spawn = true;
  10474. if (spawn_script) {
  10475. lua_State* state = lua_interface->GetSpawnScript(spawn_script);
  10476. if (state) {
  10477. Mutex* state_mutex = lua_interface->GetSpawnScriptMutex(spawn_script);
  10478. if (state_mutex)
  10479. state_mutex->writelock(__FUNCTION__, __LINE__);
  10480. lua_getglobal(state, "can_use_command");
  10481. if (lua_isfunction(state, lua_gettop(state))) {
  10482. lua_interface->SetSpawnValue(state, spawn);
  10483. lua_interface->SetSpawnValue(state, GetPlayer());
  10484. lua_interface->SetStringValue(state, command ? command : "");
  10485. if (lua_pcall(state, 3, 1, 0) == 0) {
  10486. should_use_spawn = lua_interface->GetBooleanValue(state, 1);
  10487. }
  10488. }
  10489. lua_interface->ResetFunctionStack(state);
  10490. if (state_mutex)
  10491. state_mutex->releasewritelock(__FUNCTION__, __LINE__);
  10492. }
  10493. }
  10494. return should_use_spawn;
  10495. }
  10496. bool Client::IsCurrentTransmuteID(int32 req_id) {
  10497. return req_id == transmuteID;
  10498. }
  10499. void Client::SetTransmuteID(int32 trans_id) {
  10500. transmuteID = trans_id;
  10501. }
  10502. int32 Client::GetTransmuteID() {
  10503. return transmuteID;
  10504. }
  10505. bool Client::HandleNewLogin(int32 account_id, int32 access_code)
  10506. {
  10507. ZoneAuthRequest* zar = zone_auth.GetAuth(account_id, access_code);
  10508. if (zar)
  10509. {
  10510. int32 charID = database.GetCharacterID(zar->GetCharacterName());
  10511. if (database.IsActiveQuery(charID))
  10512. {
  10513. delayedLogin = true;
  10514. delayedAccountID = account_id;
  10515. delayedAccessKey = access_code;
  10516. delayTimer.Start(500);
  10517. 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);
  10518. return true;
  10519. }
  10520. delayedLogin = false;
  10521. delayTimer.Disable();
  10522. firstlogin = zar->isFirstLogin();
  10523. SetReadyForSpawns(false);
  10524. ready_for_updates = false;
  10525. 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);
  10526. Client* client = zone_list.GetClientByCharName(zar->GetCharacterName());
  10527. if (client || database.loadCharacter(zar->GetCharacterName(), zar->GetAccountID(), this)) {
  10528. GetPlayer()->CalculateOfflineDebtRecovery(GetLastSavedTimeStamp());
  10529. GetPlayer()->vis_changed = false;
  10530. GetPlayer()->info_changed = false;
  10531. bool pvp_allowed = rule_manager.GetZoneRule(GetCurrentZoneID(), R_PVP, AllowPVP)->GetBool();
  10532. if (pvp_allowed)
  10533. this->GetPlayer()->SetAttackable(1);
  10534. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  10535. if (client) {
  10536. if (client->getConnection())
  10537. client->getConnection()->SendDisconnect(true);
  10538. bool restore_ld_success = false;
  10539. if (client->GetCurrentZone() && !client->IsZoning()) {
  10540. //swap players, allowing the client to resume his LD'd player (ONLY if same version of the client)
  10541. if (client->GetVersion() == version) {
  10542. client->DisableSave();
  10543. client->ReplaceGroupClient(this);
  10544. Player* current_player = GetPlayer();
  10545. SetPlayer(client->GetPlayer());
  10546. GetPlayer()->SetClient(this);
  10547. GetPlayer()->SetReturningFromLD(true);
  10548. SetCharacterID(client->GetCharacterID());
  10549. SetAccountID(client->GetAccountID());
  10550. SetAdminStatus(client->GetAdminStatus());
  10551. SetCurrentZone(GetPlayer()->GetZone());
  10552. client->SetPlayer(current_player);
  10553. GetPlayer()->ResetSavedSpawns();
  10554. restore_ld_success = true;
  10555. char tmpldname[128];
  10556. snprintf(tmpldname, 128, "%s Linkdead", GetPlayer()->GetName());
  10557. client->GetPlayer()->SetName(tmpldname, false);
  10558. }
  10559. ZoneServer* tmpZone = client->GetCurrentZone();
  10560. tmpZone->RemoveClientImmediately(client);
  10561. }
  10562. if (!restore_ld_success && !database.loadCharacter(zar->GetCharacterName(), zar->GetAccountID(), this)) {
  10563. LogWrite(ZONE__ERROR, 0, "Zone", "Error reloading LD character and loading DB character: %s", player->GetName());
  10564. ClientPacketFunctions::SendLoginDenied(this);
  10565. Disconnect();
  10566. return false;
  10567. }
  10568. }
  10569. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  10570. if (!GetCurrentZone()) {
  10571. LogWrite(ZONE__ERROR, 0, "Zone", "Error loading zone for character: %s", player->GetName());
  10572. ClientPacketFunctions::SendLoginDenied(this);
  10573. Disconnect();
  10574. return false;
  10575. }
  10576. else if (EQOpcodeManager.count(GetOpcodeVersion(version)) > 0 && getConnection()) {
  10577. getConnection()->SetClientVersion(version);
  10578. GetCurrentZone()->SetSpawnStructs(this);
  10579. connected_to_zone = true;
  10580. client_list.Remove(this); //remove from master client list
  10581. GetCurrentZone()->AddClient(this); //add to zones client list
  10582. zone_list.AddClientToMap(player->GetName(), this);
  10583. // 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.
  10584. if (GetCurrentZone()->IsLoading()) {
  10585. new_client_login = NewLoginState::LOGIN_DELAYED;
  10586. }
  10587. else {
  10588. new_client_login = NewLoginState::LOGIN_ALLOWED;
  10589. }
  10590. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  10591. if (zone_script && lua_interface)
  10592. lua_interface->RunZoneScript(zone_script, "new_client", GetCurrentZone(), GetPlayer());
  10593. }
  10594. else {
  10595. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  10596. version = 0;
  10597. ClientPacketFunctions::SendLoginDenied(this);
  10598. Disconnect();
  10599. return false;
  10600. }
  10601. }
  10602. else {
  10603. LogWrite(WORLD__ERROR, 0, "World", "Could not load character '%s' with account id of: %u", zar->GetCharacterName(), zar->GetAccountID());
  10604. ClientPacketFunctions::SendLoginDenied(this);
  10605. Disconnect();
  10606. return false;
  10607. }
  10608. zone_auth.RemoveAuth(zar);
  10609. }
  10610. else
  10611. {
  10612. LogWrite(WORLD__ERROR, 0, "World", "Invalid ZoneAuthRequest, disconnecting client.");
  10613. Disconnect();
  10614. return false;
  10615. }
  10616. return true;
  10617. }
  10618. void Client::SendSpawnChanges(set<Spawn*>& spawns) {
  10619. if (!IsReadyForUpdates())
  10620. return;
  10621. map<int32, SpawnData> info_changes;
  10622. map<int32, SpawnData> pos_changes;
  10623. map<int32, SpawnData> vis_changes;
  10624. map<int32, SpawnData> empty_changes;
  10625. int32 info_size = 0;
  10626. int32 pos_size = 0;
  10627. int32 vis_size = 0;
  10628. int count = 0;
  10629. for (const auto& spawn : spawns) {
  10630. int16 index = GetPlayer()->GetIndexForSpawn(spawn);
  10631. if (index == 0 || !GetPlayer()->WasSentSpawn(spawn->GetID()))
  10632. continue;
  10633. if (GetPlayer() == spawn && GetVersion() <= 284) { // stopped self client/player warping in the EQ2 release disc (Beta), don't send yourself in bulk spawn updates
  10634. continue;
  10635. }
  10636. int16 tmp_info_size = 0;
  10637. int16 tmp_pos_size = 0;
  10638. int16 tmp_vis_size = 0;
  10639. if (spawn->vis_changed)
  10640. {
  10641. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion(), &tmp_vis_size);
  10642. if (vis_change) {
  10643. SpawnData data;
  10644. data.spawn = spawn;
  10645. data.data = vis_change;
  10646. data.size = tmp_vis_size;
  10647. map<int32, SpawnData> tmp_vis_changes;
  10648. tmp_vis_changes[index] = data;
  10649. map<int32, SpawnData> tmp_info_changes;
  10650. map<int32, SpawnData> tmp_pos_changes;
  10651. if (spawn->info_changed) {
  10652. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion(), &tmp_info_size);
  10653. if (info_change) {
  10654. SpawnData data;
  10655. data.spawn = spawn;
  10656. data.data = info_change;
  10657. data.size = tmp_info_size;
  10658. tmp_info_changes[index] = data;
  10659. }
  10660. }
  10661. if (spawn->position_changed) {
  10662. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion(), &tmp_pos_size);
  10663. if (pos_change) {
  10664. SpawnData data;
  10665. data.spawn = spawn;
  10666. data.data = pos_change;
  10667. data.size = tmp_pos_size;
  10668. tmp_pos_changes[index] = data;
  10669. }
  10670. }
  10671. MakeSpawnChangePacket(tmp_info_changes, tmp_pos_changes, tmp_vis_changes, tmp_info_size, tmp_pos_size, data.size);
  10672. for (auto& kv : tmp_info_changes) {
  10673. safe_delete_array(kv.second.data);
  10674. }
  10675. for (auto& kv : tmp_pos_changes) {
  10676. safe_delete_array(kv.second.data);
  10677. }
  10678. for (auto& kv : tmp_vis_changes) {
  10679. safe_delete_array(kv.second.data);
  10680. }
  10681. continue;
  10682. }
  10683. }
  10684. if (spawn->info_changed) {
  10685. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion(), &tmp_info_size);
  10686. if (info_change) {
  10687. SpawnData data;
  10688. data.spawn = spawn;
  10689. data.data = info_change;
  10690. data.size = tmp_info_size;
  10691. info_size += tmp_info_size;
  10692. info_changes[index] = data;
  10693. }
  10694. count++;
  10695. }
  10696. if (spawn->position_changed) {
  10697. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion(), &tmp_pos_size);
  10698. if (pos_change) {
  10699. SpawnData data;
  10700. data.spawn = spawn;
  10701. data.data = pos_change;
  10702. data.size = tmp_pos_size;
  10703. pos_size += tmp_pos_size;
  10704. pos_changes[index] = data;
  10705. }
  10706. count++;
  10707. }
  10708. if (spawn->vis_changed) {
  10709. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion(), &tmp_vis_size);
  10710. if (vis_change) {
  10711. SpawnData data;
  10712. data.spawn = spawn;
  10713. data.data = vis_change;
  10714. data.size = tmp_vis_size;
  10715. vis_size += tmp_vis_size;
  10716. vis_changes[index] = data;
  10717. }
  10718. count++;
  10719. }
  10720. }
  10721. if (info_size == 0 && pos_size == 0 && vis_size == 0) {
  10722. return;
  10723. }
  10724. MakeSpawnChangePacket(info_changes, pos_changes, vis_changes, info_size, pos_size, vis_size);
  10725. for (auto& kv : info_changes) {
  10726. safe_delete_array(kv.second.data);
  10727. }
  10728. for (auto& kv : pos_changes) {
  10729. safe_delete_array(kv.second.data);
  10730. }
  10731. for (auto& kv : vis_changes) {
  10732. safe_delete_array(kv.second.data);
  10733. }
  10734. }
  10735. 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)
  10736. {
  10737. static const int8 oversized = 255;
  10738. int16 opcode_val = 0;
  10739. if (EQOpcodeManager.count(GetOpcodeVersion(version)) != 0) {
  10740. opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd);
  10741. }
  10742. int32 size = info_size + pos_size + vis_size + 8;
  10743. size += CheckOverLoadSize(info_size);
  10744. size += CheckOverLoadSize(pos_size);
  10745. size += CheckOverLoadSize(vis_size);
  10746. if (version <= 373 && size >= 255) {//1 byte to 3 for overloaded val
  10747. size += 2;
  10748. }
  10749. else if (version >= 374)
  10750. size += 3;
  10751. uchar* tmp = new uchar[size];
  10752. uchar* ptr = tmp;
  10753. memset(tmp, 0, size);
  10754. if (version <= 373) {
  10755. if (size >= 255) {
  10756. size -= 3;
  10757. memcpy(ptr, &oversized, sizeof(int8));
  10758. ptr += sizeof(int8);
  10759. memcpy(ptr, &size, sizeof(int16));
  10760. ptr += sizeof(int16);
  10761. size += 3;
  10762. }
  10763. else {
  10764. size -= 1;
  10765. memcpy(ptr, &size, sizeof(int8));
  10766. ptr += sizeof(int8);
  10767. size += 1;
  10768. }
  10769. }
  10770. else {
  10771. size -= 4;
  10772. memcpy(ptr, &size, sizeof(int32));
  10773. ptr += sizeof(int32);
  10774. size += 4;
  10775. }
  10776. memcpy(ptr, &oversized, sizeof(int8));
  10777. ptr += sizeof(int8);
  10778. memcpy(ptr, &opcode_val, sizeof(int16));
  10779. ptr += sizeof(int16);
  10780. int32 current_time = Timer::GetCurrentTime2();
  10781. memcpy(ptr, &current_time, sizeof(int32));
  10782. ptr += sizeof(int32);
  10783. ptr += DoOverLoad(info_size, ptr);
  10784. for (const auto& kv : info_changes) {
  10785. auto info = kv.second;
  10786. memcpy(ptr, info.data, info.size);
  10787. ptr += info.size;
  10788. }
  10789. ptr += DoOverLoad(pos_size, ptr);
  10790. for (const auto& kv : pos_changes) {
  10791. auto pos = kv.second;
  10792. memcpy(ptr, pos.data, pos.size);
  10793. ptr += pos.size;
  10794. }
  10795. ptr += DoOverLoad(vis_size, ptr);
  10796. for (const auto& kv : vis_changes) {
  10797. auto vis = kv.second;
  10798. memcpy(ptr, vis.data, vis.size);
  10799. ptr += vis.size;
  10800. }
  10801. EQ2Packet* packet = new EQ2Packet(OP_ClientCmdMsg, tmp, size);
  10802. if (packet) {
  10803. /*char blah[64];
  10804. snprintf(blah, 64, "Sending %i", current_time);
  10805. SimpleMessage(4, blah);*/
  10806. QueuePacket(packet);
  10807. }
  10808. delete[] tmp;
  10809. }
  10810. void Client::SendHailCommand(Spawn* spawn)
  10811. {
  10812. // hardcoded 'hail' entity commands
  10813. switch (spawn->secondary_command_list_id)
  10814. {
  10815. case 9:
  10816. case 1262:
  10817. case 1265:
  10818. case 1267:
  10819. {
  10820. EQ2_16BitString* command = new EQ2_16BitString();
  10821. command->data = "";
  10822. command->size = 0;
  10823. commands.Process(COMMAND_HAIL, command, this, spawn);
  10824. safe_delete(command);
  10825. break;
  10826. }
  10827. }
  10828. }
  10829. void Client::SendDefaultCommand(Spawn* spawn, const char* command, float distance)
  10830. {
  10831. if (GetPlayer()->WasSentSpawn(spawn->GetID())) {
  10832. PacketStruct* packet = configReader.getStruct("WS_SetDefaultCommand", GetVersion());
  10833. if (packet) {
  10834. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  10835. packet->setMediumStringByName("command_name", command);
  10836. packet->setDataByName("distance", distance);
  10837. QueuePacket(packet->serialize());
  10838. safe_delete(packet);
  10839. }
  10840. }
  10841. }
  10842. bool Client::HandleHouseEntityCommands(Spawn* spawn, int32 spawnid, string command)
  10843. {
  10844. if (GetCurrentZone()->GetInstanceType() != PERSONAL_HOUSE_INSTANCE)
  10845. return false;
  10846. if (command == "house_spawn_examine")
  10847. {
  10848. uint32 itemID = spawn->GetPickupItemID();
  10849. if (itemID)
  10850. {
  10851. Item* item = master_item_list.GetItem(itemID);
  10852. if (item)
  10853. {
  10854. EQ2Packet* app = item->serialize(GetVersion(), true, GetPlayer());
  10855. //DumpPacket(app);
  10856. QueuePacket(app);
  10857. }
  10858. }
  10859. return true;
  10860. }
  10861. return false;
  10862. }
  10863. bool Client::PopulateHouseSpawn(PacketStruct* place_object)
  10864. {
  10865. if (GetTempPlacementSpawn())
  10866. {
  10867. Spawn* tmp = GetTempPlacementSpawn();
  10868. int32 spawn_group_id = database.GetNextSpawnLocation();
  10869. tmp->SetSpawnLocationID(spawn_group_id);
  10870. float newHeading = place_object->getType_float_ByName("heading") + 180;
  10871. int32 spawnDBID = 0;
  10872. if (GetCurrentZone()->house_object_database_lookup.count(tmp->GetModelType()) > 0)
  10873. {
  10874. spawnDBID = GetCurrentZone()->house_object_database_lookup.Get(tmp->GetModelType());
  10875. tmp->SetDatabaseID(spawnDBID);
  10876. }
  10877. else
  10878. {
  10879. spawnDBID = database.FindHouseInstanceSpawn(tmp);
  10880. if (spawnDBID)
  10881. {
  10882. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), spawnDBID);
  10883. tmp->SetDatabaseID(spawnDBID);
  10884. }
  10885. }
  10886. tmp->SetX(place_object->getType_float_ByName("x"));
  10887. tmp->SetY(place_object->getType_float_ByName("y"));
  10888. tmp->SetZ(place_object->getType_float_ByName("z"));
  10889. tmp->SetHeading(newHeading);
  10890. tmp->SetSpawnOrigX(tmp->GetX());
  10891. tmp->SetSpawnOrigY(tmp->GetY());
  10892. tmp->SetSpawnOrigZ(tmp->GetZ());
  10893. tmp->SetSpawnOrigHeading(tmp->GetHeading());
  10894. database.SaveSpawnInfo(tmp);
  10895. database.SaveSpawnEntry(tmp, "houseplacement", 100, 0, 0, 0);
  10896. if (!spawnDBID)
  10897. {
  10898. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), tmp->GetDatabaseID());
  10899. // we need to copy as to not delete the ZoneServer object_list entry this on house item pickup
  10900. GetCurrentZone()->AddObject(tmp->GetDatabaseID(), ((Object*)tmp)->Copy());
  10901. }
  10902. return true;
  10903. }
  10904. return false;
  10905. }
  10906. bool Client::PopulateHouseSpawnFinalize()
  10907. {
  10908. if (GetTempPlacementSpawn())
  10909. {
  10910. Spawn* tmp = GetTempPlacementSpawn();
  10911. GetCurrentZone()->AddSpawn(tmp);
  10912. GetCurrentZone()->SendSpawnChanges(tmp, this);
  10913. SetTempPlacementSpawn(nullptr);
  10914. int32 uniqueID = GetPlacementUniqueItemID();
  10915. Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  10916. tmp->SetPickupItemID(uniqueItem->details.item_id);
  10917. tmp->SetPickupUniqueItemID(uniqueID);
  10918. if (uniqueItem)
  10919. {
  10920. if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE)
  10921. {
  10922. Query query;
  10923. 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);
  10924. }
  10925. if (uniqueItem->GetItemScript() &&
  10926. lua_interface->RunItemScript(uniqueItem->GetItemScript(), "placed", uniqueItem, GetPlayer(), tmp))
  10927. {
  10928. uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  10929. }
  10930. if (uniqueItem) {
  10931. database.DeleteItem(GetCharacterID(), uniqueItem, 0);
  10932. GetPlayer()->item_list.RemoveItem(uniqueItem, true);
  10933. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  10934. }
  10935. SetPlacementUniqueItemID(0);
  10936. }
  10937. return true;
  10938. }
  10939. return false;
  10940. }
  10941. void Client::SendMoveObjectMode(Spawn* spawn, uint8 placementMode, float unknown2_3)
  10942. {
  10943. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", GetVersion());
  10944. packet->setDataByName("placement_mode", placementMode);
  10945. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  10946. packet->setDataByName("model_type", spawn->GetModelType());
  10947. packet->setDataByName("unknown", 1); //size
  10948. packet->setDataByName("unknown2", 1); //size 2
  10949. packet->setDataByName("unknown2", .5, 1); //size 3
  10950. packet->setDataByName("unknown2", 3, 2);
  10951. packet->setDataByName("unknown2", unknown2_3, 3);
  10952. packet->setDataByName("max_distance", 500);
  10953. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  10954. QueuePacket(packet->serialize());
  10955. safe_delete(packet);
  10956. }
  10957. void Client::SendFlightAutoMount(int32 path_id, int16 mount_id, int8 mount_red_color, int8 mount_green_color, int8 mount_blue_color)
  10958. {
  10959. SetPendingFlightPath(path_id);
  10960. ((Player*)player)->SetTempMount(((Entity*)player)->GetMount());
  10961. ((Player*)player)->SetTempMountColor(((Entity*)player)->GetMountColor());
  10962. ((Player*)player)->SetTempMountSaddleColor(((Entity*)player)->GetMountSaddleColor());
  10963. PacketStruct* packet = configReader.getStruct("WS_ReadyForTakeOff", GetVersion());
  10964. if (packet) {
  10965. QueuePacket(packet->serialize());
  10966. safe_delete(packet);
  10967. }
  10968. if (mount_id)
  10969. ((Entity*)GetPlayer())->SetMount(mount_id, mount_red_color, mount_green_color, mount_blue_color);
  10970. }
  10971. void Client::SendShowBook(Spawn* sender, string title, int8 language, int8 num_pages, ...)
  10972. {
  10973. if (!sender)
  10974. {
  10975. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  10976. return;
  10977. }
  10978. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  10979. if (!packet) {
  10980. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  10981. return;
  10982. }
  10983. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  10984. packet->setDataByName("book_title", title.c_str());
  10985. packet->setDataByName("book_type", "simple");
  10986. packet->setDataByName("unknown2", 1);
  10987. if (language > 0 && !GetPlayer()->HasLanguage(language))
  10988. packet->setDataByName("language", language);
  10989. if (GetVersion() > 561)
  10990. packet->setDataByName("unknown5", 1, 4);
  10991. packet->setArrayLengthByName("num_pages", num_pages);
  10992. va_list args;
  10993. va_start(args, num_pages);
  10994. std::string endString("");
  10995. for (int8 p = 0; p < num_pages; p++)
  10996. {
  10997. std::string page = va_arg(args, string);
  10998. switch (GetVersion())
  10999. {
  11000. // release client
  11001. case 283:
  11002. case 373: // trial isle client
  11003. {
  11004. endString.append(page);
  11005. break;
  11006. }
  11007. // DoF trial
  11008. case 546:
  11009. case 561:
  11010. {
  11011. if (p == 0)
  11012. packet->setDataByName("cover_page", page.c_str());
  11013. else
  11014. packet->setArrayDataByName("page_text", page.c_str(), p - 1);
  11015. break;
  11016. }
  11017. // all other clients
  11018. default:
  11019. {
  11020. packet->setArrayDataByName("page_text", page.c_str(), p);
  11021. break;
  11022. }
  11023. }
  11024. }
  11025. if (GetVersion() <= 373)
  11026. {
  11027. packet->setDataByName("page_text", endString.c_str());
  11028. }
  11029. va_end(args);
  11030. QueuePacket(packet->serialize());
  11031. safe_delete(packet);
  11032. }
  11033. void Client::SendShowBook(Spawn* sender, string title, int8 language, vector<Item::BookPage*> pages)
  11034. {
  11035. if (!sender)
  11036. {
  11037. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  11038. return;
  11039. }
  11040. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  11041. if (!packet) {
  11042. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  11043. return;
  11044. }
  11045. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  11046. packet->setDataByName("book_title", title.c_str());
  11047. packet->setDataByName("book_type", "simple");
  11048. packet->setDataByName("unknown2", 1);
  11049. if (language > 0 && !GetPlayer()->HasLanguage(language))
  11050. packet->setDataByName("language", language);
  11051. if (GetVersion() > 561)
  11052. packet->setDataByName("unknown5", 1, 4);
  11053. packet->setArrayLengthByName("num_pages", pages.size());
  11054. std::string endString("");
  11055. for (int8 p = 0; p < pages.size(); p++)
  11056. {
  11057. Item::BookPage* page = pages[p];
  11058. std::string pageText = string(page->page_text.data);
  11059. switch (GetVersion())
  11060. {
  11061. // release client
  11062. case 283:
  11063. case 373: // trial isle client
  11064. {
  11065. endString.append(pageText);
  11066. break;
  11067. }
  11068. // DoF trial
  11069. case 546:
  11070. case 561:
  11071. {
  11072. if (p == 0)
  11073. packet->setDataByName("cover_page", pageText.c_str());
  11074. else
  11075. packet->setArrayDataByName("page_text", pageText.c_str(), p - 1);
  11076. break;
  11077. }
  11078. // all other clients
  11079. default:
  11080. {
  11081. int8 valign = int8(page->valign);
  11082. int8 halign = int8(page->halign);
  11083. packet->setArrayDataByName("page_text", pageText.c_str(), p);
  11084. packet->setArrayDataByName("page_text_valign", valign, p);
  11085. packet->setArrayDataByName("page_text_halign", halign, p);
  11086. break;
  11087. }
  11088. }
  11089. }
  11090. if (GetVersion() == 283)
  11091. {
  11092. packet->setDataByName("page_text", endString.c_str());
  11093. }
  11094. QueuePacket(packet->serialize());
  11095. safe_delete(packet);
  11096. }
  11097. void Client::ReplaceGroupClient(Client* new_client)
  11098. {
  11099. if (this->GetPlayer()->GetGroupMemberInfo())
  11100. {
  11101. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  11102. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  11103. if (group)
  11104. {
  11105. group->MGroupMembers.writelock();
  11106. rejoin_group_id = this->GetPlayer()->GetGroupMemberInfo()->group_id;
  11107. this->GetPlayer()->GetGroupMemberInfo()->client = new_client;
  11108. this->GetPlayer()->GetGroupMemberInfo()->member = GetPlayer();
  11109. group->MGroupMembers.releasewritelock();
  11110. }
  11111. else
  11112. {
  11113. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  11114. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  11115. this->GetPlayer()->SetGroupMemberInfo(0);
  11116. }
  11117. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  11118. }
  11119. }
  11120. void Client::TempRemoveGroup()
  11121. {
  11122. if (this->GetPlayer()->GetGroupMemberInfo())
  11123. {
  11124. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  11125. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  11126. if (group)
  11127. {
  11128. group->MGroupMembers.writelock();
  11129. rejoin_group_id = this->GetPlayer()->GetGroupMemberInfo()->group_id;
  11130. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  11131. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  11132. this->GetPlayer()->SetGroupMemberInfo(0);
  11133. group->MGroupMembers.releasewritelock();
  11134. group->RemoveClientReference(this);
  11135. }
  11136. else
  11137. {
  11138. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  11139. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  11140. this->GetPlayer()->SetGroupMemberInfo(0);
  11141. }
  11142. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  11143. }
  11144. }
  11145. void Client::CreateMail(int32 charID, std::string fromName, std::string subjectName, std::string mailBody,
  11146. int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time)
  11147. {
  11148. Mail mail;
  11149. mail.mail_id = 0;
  11150. mail.already_read = 0;
  11151. mail.postage_cost = 0;
  11152. mail.attachment_cost = 0;
  11153. mail.save_needed = 1;
  11154. //uhh...mail has std::strings so
  11155. //memset(&mail,0,sizeof(Mail));
  11156. mail.player_to_id = charID;
  11157. mail.player_from = fromName;
  11158. mail.subject = subjectName;
  11159. mail.mail_body = mailBody;
  11160. mail.mail_type = mailType;
  11161. mail.coin_copper = copper;
  11162. mail.coin_silver = silver;
  11163. mail.coin_gold = gold;
  11164. mail.coin_plat = platinum;
  11165. mail.char_item_id = item_id;
  11166. mail.stack = stack_size;
  11167. mail.time_sent = time_sent;
  11168. mail.expire_time = expire_time;
  11169. database.SavePlayerMail(&mail);
  11170. }
  11171. void Client::CreateAndUpdateMail(std::string fromName, std::string subjectName, std::string mailBody,
  11172. int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time)
  11173. {
  11174. Mail* mail = new Mail();
  11175. mail->player_to_id = GetCharacterID();
  11176. mail->player_from = fromName;
  11177. mail->subject = subjectName;
  11178. mail->mail_body = mailBody;
  11179. mail->mail_type = mailType;
  11180. mail->coin_copper = copper;
  11181. mail->coin_silver = silver;
  11182. mail->coin_gold = gold;
  11183. mail->coin_plat = platinum;
  11184. mail->char_item_id = item_id;
  11185. mail->stack = stack_size;
  11186. mail->time_sent = time_sent;
  11187. mail->expire_time = expire_time;
  11188. mail->postage_cost = 0;
  11189. mail->save_needed = 1;
  11190. mail->already_read = 0;
  11191. database.SavePlayerMail(mail);
  11192. GetPlayer()->AddMail(mail);
  11193. }
  11194. void Client::SendEquipOrInvUpdateBySlot(int8 slot)
  11195. {
  11196. if (slot < NUM_SLOTS)
  11197. {
  11198. EQ2Packet* app = GetPlayer()->GetEquipmentList()->serialize(GetVersion(), GetPlayer());
  11199. if (app)
  11200. QueuePacket(app);
  11201. }
  11202. else
  11203. {
  11204. EQ2Packet* outapp = GetPlayer()->SendInventoryUpdate(GetVersion());
  11205. if (outapp)
  11206. QueuePacket(outapp);
  11207. }
  11208. }
  11209. void Client::QueueStateCommand(int32 spawn_player_id, int32 state)
  11210. {
  11211. if (spawn_player_id < 1)
  11212. return;
  11213. MQueueStateCmds.writelock();
  11214. queued_state_commands.insert(make_pair(spawn_player_id, state));
  11215. MQueueStateCmds.releasewritelock();
  11216. }
  11217. void Client::ProcessStateCommands()
  11218. {
  11219. if (!IsReadyForUpdates())
  11220. return;
  11221. MQueueStateCmds.writelock();
  11222. map<int32, int32>::iterator itr = queued_state_commands.begin();
  11223. for (; itr != queued_state_commands.end(); itr++)
  11224. ClientPacketFunctions::SendStateCommand(this, itr->first, itr->second);
  11225. queued_state_commands.clear();
  11226. MQueueStateCmds.releasewritelock();
  11227. }
  11228. void Client::PurgeItem(Item* item)
  11229. {
  11230. std::unique_lock lock(MConversation);
  11231. map<int32, Item*>::iterator itr;
  11232. for (itr = conversation_items.begin(); itr != conversation_items.end(); itr++)
  11233. {
  11234. if (itr->second == item)
  11235. {
  11236. conversation_items.erase(itr);
  11237. break;
  11238. }
  11239. }
  11240. }
  11241. void Client::ConsumeFoodDrink(Item* item, int32 slot)
  11242. {
  11243. if (GetPlayer()->StopSaveSpellEffects())
  11244. return;
  11245. if (item) {
  11246. LogWrite(MISC__INFO, 1, "Command", "ItemID: %u, ItemName: %s ItemCount: %i ", item->details.item_id, item->name.c_str(), item->details.count);
  11247. if (item->GetItemScript() && lua_interface) {
  11248. lua_interface->RunItemScript(item->GetItemScript(), "cast", item, GetPlayer());
  11249. if (slot == 22) {
  11250. Message(CHANNEL_NARRATIVE, "You eat a %s.", item->name.c_str());
  11251. GetPlayer()->SetActiveFoodUniqueID(item->details.unique_id);
  11252. }
  11253. else {
  11254. Message(CHANNEL_NARRATIVE, "You drink a %s.", item->name.c_str());
  11255. GetPlayer()->SetActiveDrinkUniqueID(item->details.unique_id);
  11256. }
  11257. }
  11258. else {
  11259. Message(CHANNEL_NARRATIVE, "SERVER BUG! Item Script not assigned for consuming '%s'.", item->name.c_str());
  11260. return;
  11261. }
  11262. if (item->details.count > 1) {
  11263. item->details.count -= 1;
  11264. item->save_needed = true;
  11265. }
  11266. else {
  11267. database.DeleteItem(GetPlayer()->GetCharacterID(), item, "EQUIPPED");
  11268. GetPlayer()->GetEquipmentList()->RemoveItem(slot, true);
  11269. }
  11270. GetPlayer()->SetCharSheetChanged(true);
  11271. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  11272. if (GetVersion() <= 373) {
  11273. EQ2Packet* outapp = GetPlayer()->SendInventoryUpdate(GetVersion());
  11274. QueuePacket(outapp);
  11275. }
  11276. }
  11277. }
  11278. void Client::AwardCoins(int64 total_coins, std::string reason)
  11279. {
  11280. if (total_coins > 0) {
  11281. player->AddCoins(total_coins);
  11282. PlaySound("coin_cha_ching");
  11283. char tmp[64] = { 0 };
  11284. string message = "You receive ";
  11285. int32 val = 0;
  11286. if (total_coins >= 1000000) {
  11287. val = total_coins / 1000000;
  11288. total_coins -= 1000000 * val;
  11289. sprintf(tmp, "%u Platinum ", val);
  11290. message.append(tmp);
  11291. memset(tmp, 0, 64);
  11292. }
  11293. if (total_coins >= 10000) {
  11294. val = total_coins / 10000;
  11295. total_coins -= 10000 * val;
  11296. sprintf(tmp, "%u Gold ", val);
  11297. message.append(tmp);
  11298. memset(tmp, 0, 64);
  11299. }
  11300. if (total_coins >= 100) {
  11301. val = total_coins / 100;
  11302. total_coins -= 100 * val;
  11303. sprintf(tmp, "%u Silver ", val);
  11304. message.append(tmp);
  11305. memset(tmp, 0, 64);
  11306. }
  11307. if (total_coins > 0) {
  11308. sprintf(tmp, "%u Copper ", (int32)total_coins);
  11309. message.append(tmp);
  11310. }
  11311. message.append(reason);
  11312. int8 type = CHANNEL_LOOT;
  11313. SimpleMessage(type, message.c_str());
  11314. }
  11315. }
  11316. void Client::TriggerSpellSave()
  11317. {
  11318. int32 interval = rule_manager.GetZoneRule(GetCurrentZoneID(), R_Spells, PlayerSpellSaveStateWaitInterval)->GetInt32();
  11319. // default to not have some bogus value in the rule
  11320. if (interval < 1)
  11321. interval = 100;
  11322. MSaveSpellStateMutex.lock();
  11323. if (!save_spell_state_timer.Enabled())
  11324. {
  11325. save_spell_state_time_bucket = 0;
  11326. save_spell_state_timer.Start(interval, true);
  11327. }
  11328. else
  11329. {
  11330. int32 elapsed_time = save_spell_state_timer.GetElapsedTime();
  11331. save_spell_state_time_bucket += elapsed_time;
  11332. int32 save_wait_cap = rule_manager.GetZoneRule(GetCurrentZoneID(), R_Spells, PlayerSpellSaveStateCap)->GetInt32();
  11333. // default to not have some bogus value in the rule
  11334. if (save_wait_cap < interval)
  11335. save_wait_cap = interval + 1;
  11336. if (save_spell_state_time_bucket >= save_wait_cap)
  11337. {
  11338. save_spell_state_timer.Trigger();
  11339. }
  11340. }
  11341. MSaveSpellStateMutex.unlock();
  11342. }
  11343. void Client::UpdateSentSpellList() {
  11344. MSpellDetails.readlock(__FUNCTION__, __LINE__);
  11345. std::map<int32, int32>::iterator itr;
  11346. for (itr = sent_spell_details.begin(); itr != sent_spell_details.end(); itr++) {
  11347. Spell* spell = master_spell_list.GetSpell(itr->first, itr->second);
  11348. EQ2Packet* app = spell->SerializeSpell(this, false, false);
  11349. QueuePacket(app);
  11350. }
  11351. MSpellDetails.releasereadlock(__FUNCTION__, __LINE__);
  11352. }
  11353. void Client::SetTempPlacementSpawn(Spawn* tmp) {
  11354. tempPlacementSpawn = tmp;
  11355. hasSentTempPlacementSpawn = false;
  11356. if (tempPlacementSpawn)
  11357. temp_placement_timer.Start();
  11358. else
  11359. temp_placement_timer.Disable();
  11360. }
  11361. void Client::SetPlayer(Player* new_player) {
  11362. if (player && player != new_player)
  11363. zone_list.RemoveClientFromMap(player->GetName(), this);
  11364. player = new_player;
  11365. player->SetClient(this);
  11366. }
  11367. bool Client::UseItem(Item* item, Spawn* target) {
  11368. if (item && item->GetItemScript()) {
  11369. int16 item_index = item->details.index;
  11370. if (!item->CheckFlag2(INDESTRUCTABLE) && item->generic_info.condition == 0) {
  11371. SimpleMessage(CHANNEL_COLOR_RED, "This item is broken and must be repaired at a mender before it can be used");
  11372. }
  11373. else if (item->CheckFlag(EVIL_ONLY) && GetPlayer()->GetAlignment() != ALIGNMENT_EVIL) {
  11374. Message(0, "%s requires an evil race.", item->name.c_str());
  11375. }
  11376. else if (item->CheckFlag(GOOD_ONLY) && GetPlayer()->GetAlignment() != ALIGNMENT_GOOD) {
  11377. Message(0, "%s requires a good race.", item->name.c_str());
  11378. }
  11379. else if (item->generic_info.max_charges == 0 || item->generic_info.max_charges == 0xFFFF) {
  11380. lua_interface->RunItemScript(item->GetItemScript(), "used", item, player, target);
  11381. return true;
  11382. }
  11383. else {
  11384. if (item->details.count > 0) {
  11385. std::string itemName = string(item->name);
  11386. int32 item_id = item->details.item_id;
  11387. sint64 flags = 0;
  11388. if (lua_interface->RunItemScript(item->GetItemScript(), "used", item, player, target, &flags) && flags >= 0)
  11389. {
  11390. //reobtain item make sure it wasn't removed
  11391. item = player->item_list.GetItemFromIndex(item_index);
  11392. if (!item) {
  11393. 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);
  11394. return true;
  11395. }
  11396. else if (!item->generic_info.display_charges && item->generic_info.max_charges == 1) {
  11397. Message(CHANNEL_NARRATIVE, "%s is out of charges. It has been removed.", item->name.c_str());
  11398. RemoveItem(item, 1); // end of a set of charges OR an item that uses a stack count of actual item quantity
  11399. return true;
  11400. }
  11401. else
  11402. {
  11403. item->details.count--; // charges
  11404. item->save_needed = true;
  11405. QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  11406. if (!item->details.count) {
  11407. Message(CHANNEL_NARRATIVE, "%s is out of charges. It has been removed.", item->name.c_str());
  11408. RemoveItem(item, 1); // end of a set of charges OR an item that uses a stack count of actual item quantity
  11409. }
  11410. return true;
  11411. }
  11412. }
  11413. else {
  11414. 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);
  11415. return true;
  11416. }
  11417. }
  11418. else
  11419. {
  11420. //reobtain item make sure it wasn't removed
  11421. item = player->item_list.GetItemFromIndex(item_index);
  11422. SimpleMessage(CHANNEL_COLOR_YELLOW, "Item is out of charges.");
  11423. if (item) {
  11424. 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);
  11425. }
  11426. }
  11427. }
  11428. }
  11429. return false;
  11430. }
  11431. void Client::SendPlayFlavor(Spawn* spawn, int8 language, VoiceOverStruct* non_garble,
  11432. VoiceOverStruct* garble, bool success, bool garble_success) {
  11433. VoiceOverStruct* resStruct = nullptr;
  11434. if (language == 0 || GetPlayer()->HasLanguage(language)) {
  11435. if (success) {
  11436. resStruct = non_garble;
  11437. }
  11438. }
  11439. else if (garble_success) {
  11440. resStruct = garble;
  11441. }
  11442. if (resStruct) {
  11443. 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);
  11444. }
  11445. }
  11446. void Client::SaveQuestRewardData(bool force_refresh) {
  11447. Query query;
  11448. if (force_refresh) {
  11449. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete from character_quest_rewards where char_id = %u",
  11450. GetCharacterID());
  11451. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete from character_quest_temporary_rewards where char_id = %u",
  11452. GetCharacterID());
  11453. }
  11454. vector<QuestRewardData*>::iterator itr;
  11455. vector<QuestRewardData*> tmp_quest_rewards;
  11456. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  11457. int index = 0;
  11458. for (itr = quest_pending_reward.begin(); itr != quest_pending_reward.end(); itr++) {
  11459. int32 questID = (*itr)->quest_id;
  11460. if (!(*itr)->db_saved || force_refresh) {
  11461. 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')",
  11462. 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());
  11463. (*itr)->db_saved = true;
  11464. (*itr)->db_index = index;
  11465. if (questID && (*itr)->is_temporary) {
  11466. std::vector<Item*> items;
  11467. GetPlayer()->GetQuestTemporaryRewards(questID, &items);
  11468. if (!force_refresh && items.size() > 0) {
  11469. query.AddQueryAsync(GetCharacterID(), &database, Q_REPLACE, "delete from character_quest_temporary_rewards where char_id = %u and quest_id = %u",
  11470. GetCharacterID(), questID);
  11471. }
  11472. for (int i = 0; i < items.size(); i++) {
  11473. query.AddQueryAsync(GetCharacterID(), &database, Q_REPLACE, "replace into character_quest_temporary_rewards (char_id, quest_id, item_id, count) values(%u, %u, %u, %u)",
  11474. GetCharacterID(), questID, items[i]->details.item_id, items[i]->details.count);
  11475. }
  11476. }
  11477. }
  11478. index++;
  11479. }
  11480. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  11481. }
  11482. void Client::UpdateCharacterRewardData(QuestRewardData* data) {
  11483. if (!data)
  11484. return;
  11485. if (data->db_saved) {
  11486. Query query;
  11487. 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",
  11488. 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);
  11489. }
  11490. }
  11491. void Client::AddRecipeToPlayerPack(Recipe* recipe, PacketStruct* packet, int16* i) {
  11492. int index = 0;
  11493. if (recipe == nullptr)
  11494. return;
  11495. PlayerRecipeList* prl = GetPlayer()->GetRecipeList();
  11496. if (prl->GetRecipe(recipe->GetID())) {
  11497. delete recipe;
  11498. return;
  11499. }
  11500. auto res = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  11501. if (res != devices.end())
  11502. index = res - devices.begin();
  11503. else
  11504. devices.push_back(recipe->GetDevice());
  11505. prl->AddRecipe(recipe);
  11506. database.SavePlayerRecipe(GetPlayer(), recipe->GetID());
  11507. Message(CHANNEL_NARRATIVE, "Recipe: \"%s\" put in recipe book.", recipe->GetName());
  11508. if (packet && GetRecipeListSent()) {
  11509. packet->setArrayDataByName("id", recipe->GetID(), *i);
  11510. packet->setArrayDataByName("tier", recipe->GetTier(), *i);
  11511. packet->setArrayDataByName("level", recipe->GetLevel(), *i);
  11512. packet->setArrayDataByName("icon", recipe->GetIcon(), *i);
  11513. packet->setArrayDataByName("classes", recipe->GetClasses(), *i);
  11514. //packet->setArrayDataByName("skill", recipe->GetSkill(), *i);
  11515. packet->setArrayDataByName("technique", recipe->GetTechnique(), *i);
  11516. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), *i);
  11517. auto recipe_device = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  11518. if (recipe_device != devices.end())
  11519. packet->setArrayDataByName("device_type", recipe_device - devices.begin(), *i);
  11520. else
  11521. {//TODO error should never get here
  11522. }
  11523. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), *i);
  11524. packet->setArrayDataByName("recipe_name", recipe->GetName(), *i);
  11525. packet->setArrayDataByName("recipe_book", recipe->GetBook(), *i);
  11526. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), *i);
  11527. if (i) {
  11528. (*i)++;
  11529. }
  11530. }
  11531. }
  11532. bool Client::SetPlayerPOVGhost(Spawn* spawn) {
  11533. if (!spawn) {
  11534. pov_ghost_spawn_id = 0;
  11535. SendCharPOVGhost();
  11536. return true;
  11537. }
  11538. int32 ghost_id = player->GetIDWithPlayerSpawn(spawn);
  11539. if (ghost_id) {
  11540. pov_ghost_spawn_id = spawn->GetID();
  11541. SendCharPOVGhost();
  11542. return true;
  11543. }
  11544. return false;
  11545. }
  11546. void Client::HandleDialogSelectMsg(int32 conversation_id, int32 response_index) {
  11547. std::string conversation = "";
  11548. bool conv_established = false;
  11549. MConversation.lock_shared();
  11550. if (conversation_map.count(conversation_id) > 0 && conversation_map[conversation_id].count(response_index) > 0) {
  11551. conversation = std::string(conversation_map[conversation_id][response_index].c_str());
  11552. conv_established = true;
  11553. }
  11554. int32 spawn_id = conversation_spawns[conversation_id];
  11555. Item* item = conversation_items[conversation_id];
  11556. MConversation.unlock_shared();
  11557. if (GetCurrentZone()) {
  11558. Spawn* spawn = nullptr;
  11559. if (spawn_id) {
  11560. spawn = GetCurrentZone()->GetSpawnByID(spawn_id);
  11561. }
  11562. if (conv_established) {
  11563. if (spawn) {
  11564. if (conversation == "CloseItemConversation") {
  11565. LogWrite(LUA__ERROR, 0, "LUA", "CloseItemConversation is an invalid function call for this conversation with spawn id %u", spawn_id);
  11566. }
  11567. else {
  11568. GetCurrentZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_CONVERSATION, player, conversation.c_str());
  11569. }
  11570. }
  11571. else if (item && lua_interface && item->GetItemScript())
  11572. lua_interface->RunItemScript(item->GetItemScript(), conversation.c_str(), item, player);
  11573. else
  11574. CloseDialog(conversation_id);
  11575. }
  11576. else
  11577. CloseDialog(conversation_id);
  11578. }
  11579. }
  11580. bool Client::SetPetName(const char* petName) {
  11581. int8 result = database.CheckNameFilter(petName, 4, 31);
  11582. if (result == BADNAMELENGTH_REPLY) {
  11583. SimpleMessage(CHANNEL_COLOR_YELLOW, "Name length is invalid, must be greater then 3 characters and less then 31.");
  11584. return false;
  11585. }
  11586. else if (result == NAMEINVALID_REPLY) {
  11587. SimpleMessage(CHANNEL_COLOR_YELLOW, "Name is invalid, can only contain letters.");
  11588. return false;
  11589. }
  11590. else if (result == NAMETAKEN_REPLY) {
  11591. SimpleMessage(CHANNEL_COLOR_YELLOW, "Name is already taken, please choose another.");
  11592. return false;
  11593. }
  11594. else if (result == NAMEFILTER_REPLY) {
  11595. SimpleMessage(CHANNEL_COLOR_YELLOW, "Name failed the filter check.");
  11596. return false;
  11597. }
  11598. else if (result == UNKNOWNERROR_REPLY) {
  11599. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unknown error while checking the name.");
  11600. return false;
  11601. }
  11602. GetPlayer()->GetInfoStruct()->set_pet_name(petName);
  11603. return true;
  11604. }
  11605. bool Client::CheckConsumptionAllowed(int16 slot, bool send_message) {
  11606. switch (slot) {
  11607. case EQ2_FOOD_SLOT: {
  11608. if (GetPlayer()->GetSpellEffectBySpellType(SPELL_TYPE_FOOD)) {
  11609. if (send_message) {
  11610. Message(CHANNEL_NARRATIVE, "If you ate anymore you would explode!");
  11611. }
  11612. return false;
  11613. }
  11614. break;
  11615. }
  11616. case EQ2_DRINK_SLOT: {
  11617. if (GetPlayer()->GetSpellEffectBySpellType(SPELL_TYPE_DRINK))
  11618. {
  11619. if (send_message) {
  11620. Message(CHANNEL_NARRATIVE, "If you drank anymore you would explode!");
  11621. }
  11622. return false;
  11623. }
  11624. break;
  11625. }
  11626. default: {
  11627. if (GetVersion() <= 373) {
  11628. Item* item = GetPlayer()->item_list.GetItemFromIndex(slot);
  11629. if (item->IsFood()) {
  11630. if (item->IsFoodFood()) {
  11631. if (GetPlayer()->GetSpellEffectBySpellType(SPELL_TYPE_FOOD)) {
  11632. if (send_message) {
  11633. Message(CHANNEL_NARRATIVE, "If you ate anymore you would explode!");
  11634. }
  11635. return false;
  11636. }
  11637. return true;
  11638. }
  11639. else if (item->IsFoodDrink()) {
  11640. if (GetPlayer()->GetSpellEffectBySpellType(SPELL_TYPE_DRINK))
  11641. {
  11642. if (send_message) {
  11643. Message(CHANNEL_NARRATIVE, "If you drank anymore you would explode!");
  11644. }
  11645. return false;
  11646. }
  11647. return true;
  11648. }
  11649. }
  11650. }
  11651. return false;
  11652. break;
  11653. }
  11654. }
  11655. return true;
  11656. }
  11657. void Client::StartLinkdeadTimer() {
  11658. if (!linkdead_timer) {
  11659. int32 LD_Timer = rule_manager.GetZoneRule(GetCurrentZoneID(), R_World, LinkDeadTimer)->GetInt32();
  11660. LogWrite(CCLIENT__DEBUG, 0, "Client", "Starting linkdead timer for %s (timer %u seconds)", GetPlayer()->GetName(), (LD_Timer / 1000));
  11661. linkdead_timer = new Timer(LD_Timer);
  11662. linkdead_timer->Enable();
  11663. if (GetPlayer()->GetGroupMemberInfo()) {
  11664. LogWrite(CCLIENT__DEBUG, 0, "Client", "Telling player %s group they are disconnecting", GetPlayer()->GetName());
  11665. world.GetGroupManager()->GroupMessage(GetPlayer()->GetGroupMemberInfo()->group_id, "%s has gone Linkdead.", GetPlayer()->GetName());
  11666. }
  11667. }
  11668. }
  11669. bool Client::IsLinkdeadTimerEnabled() {
  11670. if (linkdead_timer) {
  11671. return linkdead_timer->Enabled();
  11672. }
  11673. return false;
  11674. }
  11675. void Client::SendNewAdventureSpells() {
  11676. SendNewSpells(player->GetAdventureClass());
  11677. int8 base_class = classes.GetBaseClass(player->GetAdventureClass());
  11678. int secondary_class = classes.GetSecondaryBaseClass(player->GetAdventureClass());
  11679. if (base_class != player->GetAdventureClass()) {
  11680. SendNewSpells(base_class);
  11681. }
  11682. if (secondary_class != player->GetAdventureClass() && secondary_class != base_class) {
  11683. SendNewSpells(secondary_class);
  11684. }
  11685. }
  11686. void Client::SendNewTradeskillSpells() {
  11687. SendNewTSSpells(player->GetTradeskillClass());
  11688. int8 secondary_class = classes.GetSecondaryTSBaseClass(player->GetTradeskillClass());
  11689. if (secondary_class != player->GetTradeskillClass()) {
  11690. SendNewTSSpells(secondary_class);
  11691. }
  11692. }
  11693. bool Client::AddRecipeBookToPlayer(int32 recipe_book_id, Item* item) {
  11694. Recipe* master_recipe = master_recipebook_list.GetRecipeBooks(recipe_book_id);
  11695. if (master_recipe) {
  11696. Recipe* recipe_book = new Recipe(master_recipe);
  11697. // if valid recipe book and the player doesn't have it
  11698. if (recipe_book && recipe_book->GetLevel() > GetPlayer()->GetTSLevel()) {
  11699. if (item) {
  11700. Message(CHANNEL_NARRATIVE, "Your tradeskill level is not high enough to scribe this book.");
  11701. }
  11702. safe_delete(recipe_book);
  11703. }
  11704. else if (recipe_book && item && !recipe_book->CanUseRecipeByClass(item, GetPlayer()->GetTradeskillClass())) {
  11705. if (item) {
  11706. Message(CHANNEL_NARRATIVE, "Your tradeskill class cannot use this recipe.");
  11707. }
  11708. safe_delete(recipe_book);
  11709. }
  11710. else if (recipe_book && (!item || !(GetPlayer()->GetRecipeBookList()->HasRecipeBook(recipe_book_id)))) {
  11711. LogWrite(PLAYER__DEBUG, 0, "Recipe", "Valid recipe book that the player doesn't have");
  11712. // Add recipe book to the players list
  11713. if (!GetPlayer()->GetRecipeBookList()->HasRecipeBook(recipe_book_id)) {
  11714. GetPlayer()->GetRecipeBookList()->AddRecipeBook(recipe_book);
  11715. }
  11716. std::vector<Recipe*> recipes;
  11717. // Get a list of all recipes this book contains
  11718. if (item && item->recipebook_info) {
  11719. //Backup I guess if the recipe book is empty for whatever reason?
  11720. for (auto& itr : item->recipebook_info->recipes) {
  11721. Recipe* r = master_recipe_list.GetRecipeByCRC(itr); //GetRecipeByName(itr.c_str());
  11722. if (r) {
  11723. recipes.push_back(r);
  11724. }
  11725. }
  11726. LogWrite(PLAYER__DEBUG, 0, "Recipe", "%i recipes found for %s book", recipes.size(), recipe_book->GetBookName());
  11727. }
  11728. else {
  11729. LogWrite(PLAYER__ERROR, 0, "Recipe", "no recipes found for %s book", recipe_book->GetBookName());
  11730. }
  11731. //Filter out duplicate recipes the player already has
  11732. for (auto itr = recipes.begin(); itr != recipes.end();) {
  11733. Recipe* recipe = *itr;
  11734. if (GetPlayer()->GetRecipeList()->GetRecipe(recipe->GetID())) {
  11735. itr = recipes.erase(itr);
  11736. }
  11737. else itr++;
  11738. }
  11739. int16 i = 0;
  11740. // Create the packet to send to update the players recipe list
  11741. PacketStruct* packet = 0;
  11742. if (!recipes.empty() && GetRecipeListSent()) {
  11743. packet = configReader.getStruct("WS_RecipeList", GetVersion());
  11744. if (packet) {
  11745. packet->setArrayLengthByName("num_recipes", recipes.size());
  11746. }
  11747. }
  11748. for (int32 r = 0; r < recipes.size(); r++) {
  11749. Recipe* recipe = recipes[r];
  11750. if (recipe) {
  11751. Recipe* player_recipe = new Recipe(recipe);
  11752. AddRecipeToPlayerPack(player_recipe, packet, &i);
  11753. }
  11754. }
  11755. LogWrite(TRADESKILL__DEBUG, 0, "Recipe", "Done adding recipes");
  11756. database.SavePlayerRecipeBook(GetPlayer(), recipe_book->GetBookID());
  11757. if (item) {
  11758. database.DeleteItem(GetCharacterID(), item, 0);
  11759. GetPlayer()->item_list.RemoveItem(item, true);
  11760. }
  11761. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  11762. SetRecipeListSent(false);
  11763. SendRecipeList();
  11764. safe_delete(packet);
  11765. return true;
  11766. }
  11767. else {
  11768. if (recipe_book && item) {
  11769. Message(CHANNEL_NARRATIVE, "You have already learned all you can from this item.");
  11770. }
  11771. safe_delete(recipe_book);
  11772. }
  11773. }
  11774. else {
  11775. LogWrite(PLAYER__ERROR, 0, "Player", "%u recipe book id does not exist. Cannot AddRecipeToPlayer.", recipe_book_id);
  11776. }
  11777. return false;
  11778. }
  11779. bool Client::RemoveRecipeFromPlayer(int32 recipe_id) {
  11780. PlayerRecipeList* prl = GetPlayer()->GetRecipeList();
  11781. PacketStruct* packet = configReader.getStruct("WS_RecipeList", version);
  11782. Recipe* recipe = prl->GetRecipe(recipe_id);
  11783. int8 level = player->GetTSLevel();
  11784. if (packet && recipe) {
  11785. packet->setDataByName("command_type", 1);
  11786. packet->setArrayLengthByName("num_recipes", 1);
  11787. int32 myid = recipe->GetID();
  11788. int8 rlevel = recipe->GetLevel();
  11789. int8 even = level - level * .05 + .5;
  11790. int8 easymin = level - level * .25 + .5;
  11791. int8 veasymin = level - level * .35 + .5;
  11792. if (rlevel > level)
  11793. packet->setArrayDataByName("tier", 4, 0);
  11794. else if ((rlevel <= level) & (rlevel >= even))
  11795. packet->setArrayDataByName("tier", 3, 0);
  11796. else if ((rlevel <= even) & (rlevel >= easymin))
  11797. packet->setArrayDataByName("tier", 2, 0);
  11798. else if ((rlevel <= easymin) & (rlevel >= veasymin))
  11799. packet->setArrayDataByName("tier", 1, 0);
  11800. else if ((rlevel <= veasymin) & (rlevel >= 0))
  11801. packet->setArrayDataByName("tier", 0, 0);
  11802. if (rlevel == 2)
  11803. int xxx = 1;
  11804. packet->setArrayDataByName("recipe_id", myid, 0);
  11805. packet->setArrayDataByName("level", recipe->GetLevel(), 0);
  11806. packet->setArrayDataByName("unknown1", recipe->GetLevel(), 0);
  11807. packet->setArrayDataByName("icon", recipe->GetIcon(), 0);
  11808. packet->setArrayDataByName("classes", recipe->GetClasses(), 0);
  11809. packet->setArrayDataByName("technique", recipe->GetTechnique(), 0);
  11810. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), 0);
  11811. auto recipe_device = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  11812. if (recipe_device != devices.end())
  11813. packet->setArrayDataByName("device_type", recipe_device - devices.begin(), 0);
  11814. else
  11815. {//TODO error should never get here
  11816. }
  11817. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), 0);
  11818. packet->setArrayDataByName("recipe_name", recipe->GetName(), 0);
  11819. packet->setArrayDataByName("recipe_book", recipe->GetBook(), 0);
  11820. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), 0);
  11821. QueuePacket(packet->serialize());
  11822. }
  11823. safe_delete(packet);
  11824. bool res = prl->RemoveRecipe(recipe_id);
  11825. if (res) {
  11826. Query query;
  11827. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "DELETE FROM character_recipes where char_id=%u and recipe_id=%u", GetCharacterID(), recipe_id);
  11828. }
  11829. return res;
  11830. }
  11831. void Client::SaveSpells() {
  11832. MSaveSpellStateMutex.lock();
  11833. player->SaveSpellEffects();
  11834. player->SetSaveSpellEffects(true);
  11835. MSaveSpellStateMutex.unlock();
  11836. }
  11837. void Client::SendReplaceWidget(int32 widget_id, bool delete_widget, float x, float y, float z, int32 grid_id) {
  11838. Widget* new_spawn = new Widget();
  11839. new_spawn->SetWidgetID(widget_id);
  11840. new_spawn->SetLocation(grid_id);
  11841. new_spawn->SetWidgetX(x);
  11842. new_spawn->SetWidgetY(y);
  11843. new_spawn->SetWidgetZ(z);
  11844. new_spawn->SetX(x);
  11845. new_spawn->SetY(y);
  11846. new_spawn->SetZ(z);
  11847. EQ2Packet* ret = new_spawn->serialize(GetPlayer(), GetVersion());
  11848. QueuePacket(ret);
  11849. // we have to delete spawn* references anyway, we don't keep this widget live in the spawn list
  11850. GetPlayer()->RemoveSpawn(new_spawn, delete_widget);
  11851. safe_delete(new_spawn);
  11852. }
  11853. void Client::ProcessZoneIgnoreWidgets() {
  11854. GetPlayer()->MIgnoredWidgets.lock_shared();
  11855. std::map<int32, bool>::iterator itr;
  11856. for (itr = GetPlayer()->ignored_widgets.begin(); itr != GetPlayer()->ignored_widgets.end(); itr++) {
  11857. SendReplaceWidget(itr->first, true);
  11858. }
  11859. GetPlayer()->MIgnoredWidgets.unlock_shared();
  11860. }
  11861. void Client::PopulateRecipeData(Recipe* recipe, PacketStruct* packet, int i) {
  11862. if (!recipe || !packet)
  11863. return;
  11864. int8 level = player->GetTSLevel();
  11865. int32 myid = recipe->GetID();
  11866. int8 rlevel = recipe->GetLevel();
  11867. int8 even = level - level * .05 + .5;
  11868. int8 easymin = level - level * .25 + .5;
  11869. int8 veasymin = level - level * .35 + .5;
  11870. if (rlevel > level)
  11871. packet->setArrayDataByName("tier", 4, i);
  11872. else if ((rlevel <= level) & (rlevel >= even))
  11873. packet->setArrayDataByName("tier", 3, i);
  11874. else if ((rlevel <= even) & (rlevel >= easymin))
  11875. packet->setArrayDataByName("tier", 2, i);
  11876. else if ((rlevel <= easymin) & (rlevel >= veasymin))
  11877. packet->setArrayDataByName("tier", 1, i);
  11878. else if ((rlevel <= veasymin) & (rlevel >= 0))
  11879. packet->setArrayDataByName("tier", 0, i);
  11880. if (rlevel == 2)
  11881. int xxx = 1;
  11882. packet->setArrayDataByName("recipe_id", myid, i);
  11883. packet->setArrayDataByName("level", recipe->GetLevel(), i);
  11884. packet->setArrayDataByName("icon", recipe->GetIcon(), i);
  11885. packet->setArrayDataByName("classes", recipe->GetClasses(), i);
  11886. packet->setArrayDataByName("technique", recipe->GetTechnique(), i);
  11887. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), i);
  11888. packet->setArrayDataByName("device", recipe->GetDevice(), i);
  11889. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), i);
  11890. packet->setArrayDataByName("recipe_name", recipe->GetName(), i);
  11891. packet->setArrayDataByName("recipe_book", recipe->GetBook(), i);
  11892. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), i);
  11893. packet->setArrayDataByName("book_volume", 0x01, i);
  11894. packet->setArrayDataByName("device_id", 0x01, i);
  11895. }
  11896. int32 Client::GetRecipeCRC(Recipe* recipe) {
  11897. PacketStruct* packet = 0;
  11898. if (!(packet = configReader.getStruct("WS_RecipeDetailList", GetVersion()))) {
  11899. return 0;
  11900. }
  11901. packet->setArrayLengthByName("num_recipes", 1);
  11902. PopulateRecipeData(recipe, packet);
  11903. string* generic_string_data = packet->serializeString();
  11904. int32 size = generic_string_data->length();
  11905. if (size < 5)
  11906. return 0;
  11907. uchar* out_data = new uchar[size + 1];
  11908. uchar* out_ptr = out_data;
  11909. memcpy(out_ptr, (uchar*)generic_string_data->c_str() + 4, generic_string_data->length() - 4);
  11910. uint32 out_crc = GenerateCRCRecipe(0, (void*)out_ptr, size - 4);
  11911. safe_delete(packet);
  11912. safe_delete_array(out_data);
  11913. return out_crc;
  11914. }
  11915. void Client::SendRecipeDetails(vector<int32>* recipes) {
  11916. if (!recipes || recipes->size() == 0)
  11917. return;
  11918. PacketStruct* packet = 0;
  11919. if (!(packet = configReader.getStruct("WS_RecipeDetailList", GetVersion()))) {
  11920. return;
  11921. }
  11922. int32 recipe_size = player->GetRecipeList()->Size();
  11923. packet->setArrayLengthByName("num_recipes", recipe_size > 100 ? 100 : recipe_size);
  11924. int16 i = 0;
  11925. int32 count = 0;
  11926. vector<int32>::iterator recipe_itr;
  11927. for (recipe_itr = recipes->begin(); recipe_itr != recipes->end(); recipe_itr++) {
  11928. Recipe* recipe = player->GetRecipeList()->GetRecipe(*recipe_itr);
  11929. if (!recipe) {
  11930. continue;
  11931. }
  11932. else if (i > 99) {
  11933. QueuePacket(packet->serialize());
  11934. safe_delete(packet);
  11935. packet = configReader.getStruct("WS_RecipeDetailList", GetVersion());
  11936. recipe_size -= i;
  11937. packet->setArrayLengthByName("num_recipes", recipe_size > 100 ? 100 : recipe_size);
  11938. i = 0;
  11939. }
  11940. count++;
  11941. PopulateRecipeData(recipe, packet, i);
  11942. i++;
  11943. }
  11944. //packet->PrintPacket();
  11945. QueuePacket(packet->serialize());
  11946. safe_delete(packet);
  11947. }
  11948. bool Client::GetHouseZoneServer(ZoneChangeDetails* zone_details, int32 spawn_id, int64 house_id) {
  11949. PlayerHouse* ph = nullptr;
  11950. HouseZone* hz = nullptr;
  11951. if (spawn_id) {
  11952. Spawn* houseWidget = GetPlayer()->GetSpawnByIndex(spawn_id);
  11953. if (houseWidget && houseWidget->IsWidget() && ((Widget*)houseWidget)->GetHouseID()) {
  11954. hz = world.GetHouseZone(((Widget*)houseWidget)->GetHouseID());
  11955. if (hz) {
  11956. ph = world.GetPlayerHouseByHouseID(GetPlayer()->GetCharacterID(), hz->id);
  11957. }
  11958. else {
  11959. Message(CHANNEL_COLOR_YELLOW, "HouseWidget spawn index %u house zone could not be found.", spawn_id);
  11960. }
  11961. }
  11962. }
  11963. if (!ph && house_id) {
  11964. ph = world.GetPlayerHouseByUniqueID(house_id);
  11965. if (ph) {
  11966. hz = world.GetHouseZone(ph->house_id);
  11967. }
  11968. }
  11969. if (ph && hz) {
  11970. if (zone_list.GetZoneByInstance(zone_details, ph->instance_id, hz->zone_id)) {
  11971. return true;
  11972. }
  11973. return false;
  11974. }
  11975. return false;
  11976. }
  11977. void Client::SendHearCast(Spawn* caster, Spawn* target, int32 spell_visual, int16 cast_time) {
  11978. PacketStruct* packet = configReader.getStruct("WS_HearCastSpell", GetVersion());
  11979. if (packet) {
  11980. int32 caster_id = GetPlayer()->GetIDWithPlayerSpawn(caster);
  11981. int32 target_id = GetPlayer()->GetIDWithPlayerSpawn(target);
  11982. packet->setDataByName("spawn_id", caster_id);
  11983. packet->setArrayLengthByName("num_targets", 1);
  11984. packet->setArrayDataByName("target", target_id);
  11985. packet->setDataByName("num_targets", 1);
  11986. int32 visual = GetSpellVisualOverride(spell_visual);
  11987. packet->setDataByName("spell_visual", visual); //result
  11988. packet->setDataByName("cast_time", cast_time * .01f); //delay
  11989. packet->setDataByName("spell_id", 1);
  11990. packet->setDataByName("spell_level", 1);
  11991. packet->setDataByName("spell_tier", 1);
  11992. EQ2Packet* outapp = packet->serialize();
  11993. //DumpPacket(outapp);
  11994. QueuePacket(outapp);
  11995. safe_delete(packet);
  11996. }
  11997. }
  11998. int32 Client::GetSpellVisualOverride(int32 spell_visual) {
  11999. int32 visual = spell_visual;
  12000. if (GetVersion() <= 561) { // spell's spell_visual field is based on newer clients, DoF has to convert
  12001. Emote* spellVisualEmote = visual_states.FindSpellVisualByID(visual, 60085);
  12002. if (spellVisualEmote != nullptr && spellVisualEmote->GetMessageString().size() > 0) {
  12003. spellVisualEmote = visual_states.FindSpellVisual(spellVisualEmote->GetMessageString(), GetVersion());
  12004. if (spellVisualEmote) {
  12005. visual = (int32)spellVisualEmote->GetVisualState();
  12006. }
  12007. }
  12008. }
  12009. return visual;
  12010. }
  12011. void Client::HandleGroupAcceptResponse(int8 result) {
  12012. if (result == 0)
  12013. SimpleMessage(CHANNEL_GROUP_CHAT, "You have joined the group.");
  12014. else if (result == 1)
  12015. SimpleMessage(CHANNEL_GROUP_CHAT, "You do not have a pending invite.");
  12016. else if (result == 2)
  12017. SimpleMessage(CHANNEL_GROUP_CHAT, "Unable to join group - could not find leader.");
  12018. else
  12019. SimpleMessage(CHANNEL_GROUP_CHAT, "Unable to join group - unknown error.");
  12020. }
  12021. void Client::SetGroupOptionsReference(GroupOptions* options) {
  12022. if (options) {
  12023. options->loot_method = GetPlayer()->GetInfoStruct()->get_group_loot_method();
  12024. options->loot_items_rarity = GetPlayer()->GetInfoStruct()->get_group_loot_items_rarity();
  12025. options->auto_split = GetPlayer()->GetInfoStruct()->get_group_auto_split();
  12026. options->default_yell = GetPlayer()->GetInfoStruct()->get_group_default_yell();
  12027. options->group_autolock = GetPlayer()->GetInfoStruct()->get_group_autolock();
  12028. options->group_lock_method = GetPlayer()->GetInfoStruct()->get_group_lock_method();
  12029. options->solo_autolock = GetPlayer()->GetInfoStruct()->get_group_solo_autolock();
  12030. options->auto_loot_method = GetPlayer()->GetInfoStruct()->get_group_auto_loot_method();
  12031. }
  12032. }
  12033. void Client::SendReceiveOffer(Client* target_client, int8 type, std::string name, int8 unknown2) {
  12034. PacketStruct* packet = configReader.getStruct("WS_ReceiveOffer", target_client->GetVersion());
  12035. if (packet) {
  12036. packet->setDataByName("type", type);
  12037. packet->setDataByName("name", name.c_str());
  12038. packet->setDataByName("unknown2", unknown2);
  12039. target_client->QueuePacket(packet->serialize());
  12040. }
  12041. safe_delete(packet);
  12042. }