9
3

client.cpp 455 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "../common/debug.h"
  17. #include "../common/Log.h"
  18. #include <iostream>
  19. #include <iomanip>
  20. #include <string.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <math.h>
  24. #include <zlib.h>
  25. #include <assert.h>
  26. #include <algorithm>
  27. #include "Player.h"
  28. #include "Commands/Commands.h"
  29. #include "ClientPacketFunctions.h"
  30. #include "../common/ConfigReader.h"
  31. #include "Guilds/Guild.h"
  32. #include "Variables.h"
  33. #include "Rules/Rules.h"
  34. #include "Titles.h"
  35. #include "Chat/Chat.h"
  36. #include "SpellProcess.h"
  37. #include "Zone/ChestTrap.h"
  38. #include "../../common/GlobalHeaders.h"
  39. //#include "Quests.h"
  40. #ifdef WIN32
  41. #include <WinSock2.h>
  42. #include <windows.h>
  43. #define snprintf _snprintf
  44. #define vsnprintf _vsnprintf
  45. #define strncasecmp _strnicmp
  46. #define strcasecmp _stricmp
  47. #else
  48. #include <sys/socket.h>
  49. #ifdef FREEBSD
  50. #include <sys/types.h>
  51. #endif
  52. #include <netinet/in.h>
  53. #include <arpa/inet.h>
  54. #include <unistd.h>
  55. #endif
  56. #if defined(__GNUC__)
  57. #define _snprintf snprintf
  58. #endif
  59. #include "client.h"
  60. #include "../common/emu_opcodes.h"
  61. #include "../common/packet_dump.h"
  62. #include "WorldDatabase.h"
  63. #include "races.h"
  64. #include "classes.h"
  65. #include "LoginServer.h"
  66. #include "World.h"
  67. #include "../common/EQ2_Common_Structs.h"
  68. #include "net.h"
  69. #include "../common/MiscFunctions.h"
  70. #include "Skills.h"
  71. #include "LuaInterface.h"
  72. #include "Quests.h"
  73. #include "Collections/Collections.h"
  74. #include "Achievements/Achievements.h"
  75. #include "Traits/Traits.h"
  76. #include "Recipes/Recipe.h"
  77. #include "Tradeskills/Tradeskills.h"
  78. #include "AltAdvancement/AltAdvancement.h"
  79. #include "Bots/Bot.h"
  80. #include "VisualStates.h"
  81. extern WorldDatabase database;
  82. extern const char* ZONE_NAME;
  83. extern LoginServer loginserver;
  84. extern sint32 numclients;
  85. extern NetConnection net;
  86. extern Commands commands;
  87. extern ClientList client_list;
  88. extern ZoneList zone_list;
  89. extern ZoneAuth zone_auth;
  90. extern MasterItemList master_item_list;
  91. extern MasterSkillList master_skill_list;
  92. extern MasterSpellList master_spell_list;
  93. extern MasterTraitList master_trait_list;
  94. extern MasterQuestList master_quest_list;
  95. extern MasterFactionList master_faction_list;
  96. extern MasterRecipeList master_recipe_list;
  97. extern volatile bool RunLoops;
  98. extern ConfigReader configReader;
  99. extern LuaInterface* lua_interface;
  100. extern World world;
  101. extern Variables variables;
  102. extern Classes classes;
  103. extern Races races;
  104. extern GuildList guild_list;
  105. extern MasterCollectionList master_collection_list;
  106. extern MasterAchievementList master_achievement_list;
  107. extern RuleManager rule_manager;
  108. extern Chat chat;
  109. extern MasterAAList master_aa_list;
  110. extern MasterAAList master_tree_nodes;
  111. extern ChestTrapList chest_trap_list;
  112. extern MasterRecipeBookList master_recipebook_list;
  113. extern VisualStates visual_states;
  114. using namespace std;
  115. Client::Client(EQStream* ieqs) : underworld_cooldown_timer(5000), pos_update(125), quest_pos_timer(2000), lua_debug_timer(30000), delayTimer(500), transmuteID(0), temp_placement_timer(10), spawn_removal_timer(250) {
  116. eqs = ieqs;
  117. ip = eqs->GetrIP();
  118. port = ntohs(eqs->GetrPort());
  119. merchant_transaction = nullptr;
  120. mail_window.item = nullptr; // don't want this to be set(loose ptr) when using ResetSendMail to provide rest of the defaults
  121. ResetSendMail(false);
  122. timestamp_flag = 0;
  123. current_quest_id = 0;
  124. last_update_time = 0;
  125. quest_updates = false;
  126. //autobootup_timeout = new Timer(10000);
  127. //autobootup_timeout->Disable();
  128. CLE_keepalive_timer = new Timer(15000);
  129. connect = new Timer(1000);
  130. connect->Disable();
  131. zoneID = 0;
  132. account_name[0] = 0;
  133. character_id = 0;
  134. account_id = 0;
  135. pwaitingforbootup = 0;
  136. current_zone = 0;
  137. connected_to_zone = false;
  138. connected = false;
  139. camp_timer = 0;
  140. linkdead_timer = 0;
  141. client_zoning = false;
  142. zoning_id = 0;
  143. zoning_x = 0;
  144. zoning_y = 0;
  145. zoning_z = 0;
  146. zoning_instance_id = 0;
  147. player_pos_changed = false;
  148. player_pos_timer = Timer::GetCurrentTime2()+1000;
  149. enabled_player_pos_timer = true;
  150. ++numclients;
  151. if (world.GetServerStatisticValue(STAT_SERVER_MOST_CONNECTIONS) < numclients)
  152. world.UpdateServerStatistic(STAT_SERVER_MOST_CONNECTIONS, numclients, true);
  153. remove_from_list = false;
  154. new_client_login = NewLoginState::LOGIN_NONE;
  155. UpdateWindowTitle(0);
  156. num_active_failures = 0;
  157. player = new Player();
  158. player->SetClient(this);
  159. combine_spawn = 0;
  160. lua_debug = false;
  161. ready_for_spawns = false;
  162. ready_for_updates = false;
  163. lua_debug_timer.Disable();
  164. transport_spawn = 0;
  165. MBuyBack.SetName("Client::MBuyBack");
  166. MDeletePlayer.SetName("Client::MDeletePlayer");
  167. MQuestPendingUpdates.SetName("Client::MQuestPendingUpdates");
  168. search_items = 0;
  169. version = 0;
  170. next_conversation_id = 0;
  171. pending_guild_invite.guild = 0;
  172. pending_guild_invite.invited_by = 0;
  173. m_recipeListSent = false;
  174. m_resurrect.SetName("Client::m_resurrect");
  175. current_rez.expire_timer = 0;
  176. current_rez.should_delete = true;
  177. pending_last_name = 0;
  178. should_target = false;
  179. initial_spawns_sent = false;
  180. MQuestTimers.SetName("Client::quest_timers");
  181. memset(&incoming_paperdoll, 0, sizeof(incoming_paperdoll));
  182. on_auto_mount = false;
  183. should_load_spells = true;
  184. spawnPlacementMode = ServerSpawnPlacementMode::DEFAULT;
  185. delayedLogin = false;
  186. delayedAccountID = 0;
  187. delayedAccessKey = 0;
  188. delayTimer.Disable();
  189. tempPlacementSpawn = nullptr;
  190. placement_unique_item_id = 0;
  191. SetHasOwnerOrEditAccess(false);
  192. temporary_transport_id = 0;
  193. rejoin_group_id = 0;
  194. lastRegionRemapTime = 0;
  195. regionDebugMessaging = false;
  196. client_reloading_zone = false;
  197. last_saved_timestamp = 0;
  198. MQueueStateCmds.SetName("Client::MQueueStateCmds");
  199. save_spell_state_timer.Disable();
  200. save_spell_state_time_bucket = 0;
  201. player_loading_complete = false;
  202. MItemDetails.SetName("Client::MItemDetails");
  203. MSpellDetails.SetName("Client::MSpellDetails");
  204. hasSentTempPlacementSpawn = false;
  205. spawn_removal_timer.Start();
  206. disable_save = false;
  207. SetZoningDestination(nullptr);
  208. underworld_cooldown_timer.Disable();
  209. player_pos_change_count = 0;
  210. pov_ghost_spawn_id = 0;
  211. recipe_orig_packet = nullptr;
  212. recipe_xor_packet = nullptr;
  213. recipe_packet_count = 0;
  214. recipe_orig_packet_size = 0;
  215. }
  216. Client::~Client() {
  217. RemoveClientFromZone();
  218. //let the stream factory know were done with this stream
  219. if (eqs) {
  220. eqs->Close();
  221. try {
  222. eqs->ReleaseFromUse();
  223. }
  224. catch (...) {}
  225. }
  226. eqs = NULL;
  227. //safe_delete(autobootup_timeout);
  228. safe_delete(linkdead_timer);
  229. vector<QueuedQuest*>::iterator itr;
  230. QueuedQuest* queued_quest = 0;
  231. for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
  232. queued_quest = *itr;
  233. safe_delete(queued_quest);
  234. }
  235. quest_queue.clear();
  236. vector<QuestRewardData*>::iterator rwd_itr;
  237. QuestRewardData* quest_rwd_data = 0;
  238. for (rwd_itr = quest_pending_reward.begin(); rwd_itr != quest_pending_reward.end(); rwd_itr++) {
  239. quest_rwd_data = *rwd_itr;
  240. safe_delete(quest_rwd_data);
  241. }
  242. quest_pending_reward.clear();
  243. safe_delete(CLE_keepalive_timer);
  244. safe_delete(connect);
  245. --numclients;
  246. UpdateWindowTitle(0);
  247. }
  248. void Client::RemoveClientFromZone() {
  249. if(player && player->GetZone())
  250. player->GetZone()->GetSpellProcess()->RemoveSpellTimersFromSpawn(player, true, false, true, true);
  251. if (GetTempPlacementSpawn() && GetCurrentZone()) {
  252. Spawn* tmp = GetTempPlacementSpawn();
  253. SetTempPlacementSpawn(nullptr);
  254. GetCurrentZone()->RemoveSpawn(tmp, true, false, true, true, true);
  255. }
  256. if (current_zone && player) {
  257. if (player->GetGroupMemberInfo()) {
  258. TempRemoveGroup();
  259. }
  260. world.GetGroupManager()->ClearPendingInvite(player);
  261. }
  262. if (lua_interface)
  263. lua_interface->RemoveDebugClients(this);
  264. if (player)
  265. zone_list.RemoveClientFromMap(player->GetName(), this);
  266. safe_delete(camp_timer);
  267. safe_delete(search_items);
  268. safe_delete(current_rez.expire_timer);
  269. safe_delete(pending_last_name);
  270. safe_delete_array(incoming_paperdoll.image_bytes);
  271. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  272. player = nullptr;
  273. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  274. deque<BuyBackItem*>::iterator itr;
  275. MBuyBack.writelock(__FUNCTION__, __LINE__);
  276. for (itr = buy_back_items.begin(); itr != buy_back_items.end();) {
  277. safe_delete(*itr);
  278. itr = buy_back_items.erase(itr);
  279. }
  280. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  281. }
  282. void Client::QueuePacket(EQ2Packet* app, bool attemptedCombine) {
  283. if (eqs) {
  284. if (!eqs->CheckActive()) {
  285. client_list.Remove(this);
  286. eqs = 0;
  287. }
  288. }
  289. if (app && eqs && version > 0)
  290. eqs->EQ2QueuePacket(app, attemptedCombine);
  291. else {
  292. safe_delete(app);
  293. }
  294. }
  295. void Client::PopulateSkillMap() {
  296. EQ2Packet* app = master_skill_list.GetPopulateSkillsPacket(GetVersion());
  297. if (app)
  298. QueuePacket(app);
  299. else {
  300. LogWrite(WORLD__ERROR, 0, "World", "Unable to send populate skills packet for version: %i!", GetVersion());
  301. Disconnect(); //the client cant proceed without the skill packet, might as well kick it now
  302. }
  303. }
  304. void Client::SendLoginInfo() {
  305. if(GetPlayer()->IsReturningFromLD())
  306. firstlogin = true;
  307. if (firstlogin) {
  308. LogWrite(WORLD__DEBUG, 0, "World", "Increment Server_Accepted_Connection + 1");
  309. world.UpdateServerStatistic(STAT_SERVER_ACCEPTED_CONNECTION, 1);
  310. LogWrite(CCLIENT__DEBUG, 0, "Client", "Populate Skill Map...");
  311. PopulateSkillMap();
  312. // JA: Check client version and move player to valid zone if current client does not support last saved zone (loading SF client on DoV saved zone) IT CAN HAPPEN!
  313. LogWrite(MISC__TODO, 1, "TODO", "Check client version at login, move char if invalid zone file");
  314. }
  315. LogWrite(CCLIENT__DEBUG, 0, "Client", "Toggle Character Online...");
  316. database.ToggleCharacterOnline(this, 1);
  317. int32 count = 0;
  318. if(!GetPlayer()->IsReturningFromLD())
  319. {
  320. count = database.LoadCharacterTitles(GetCharacterID(), player);
  321. if (count == 0) {
  322. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character titles found!");
  323. LogWrite(CCLIENT__DEBUG, 0, "Client", "Initializing starting values - Titles");
  324. database.UpdateStartingTitles(GetCharacterID(), player->GetAdventureClass(), player->GetRace(), player->GetGender());
  325. }
  326. }
  327. if(!GetPlayer()->IsReturningFromLD())
  328. {
  329. count = database.LoadCharacterLanguages(GetCharacterID(), player);
  330. if (count == 0)
  331. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character languages loaded!");
  332. count = database.LoadPlayerRecipeBooks(GetCharacterID(), player);
  333. if (count == 0)
  334. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character recipe books found!");
  335. }
  336. ClientPacketFunctions::SendLoginAccepted(this);
  337. ClientPacketFunctions::SendAbilities ( this );
  338. ClientPacketFunctions::SendCommandNamePacket(this);
  339. ClientPacketFunctions::SendQuickBarInit(this);
  340. // we only need to send the MOTD if it is the first time the person is logging in.
  341. if (firstlogin) {
  342. ClientPacketFunctions::SendMOTD(this);
  343. ClientPacketFunctions::SendCharacterMacros(this);
  344. zone_list.CheckFriendList(this);
  345. }
  346. if(!GetPlayer()->IsReturningFromLD())
  347. {
  348. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  349. if (firstlogin && player->item_list.GetNumberOfItems() == 0 && player->GetEquipmentList()->GetNumberOfItems() == 0) //re-add starting items if missing
  350. {
  351. LogWrite(CCLIENT__WARNING, 0, "Client", "Player has no items - reloading starting items: '%s' (%u)", player->GetName(), GetCharacterID());
  352. database.UpdateStartingItems(GetCharacterID(), player->GetAdventureClass(), player->GetRace());
  353. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  354. }
  355. GetPlayer()->item_list.SetMaxItemIndex();
  356. database.LoadPlayerFactions(this);
  357. database.LoadCharacterQuests(this);
  358. database.LoadCharacterQuestRewards(this);
  359. database.LoadPlayerMail(this);
  360. }
  361. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  362. SendQuestJournal(true, 0, false);
  363. if (version > 561) // right version? possibly not!
  364. master_aa_list.DisplayAA(this, 0, 3);
  365. if (version > 373)
  366. SendCollectionList();
  367. SendBiography();
  368. map<int32, Quest*>::iterator itr;
  369. Quest* quest = 0;
  370. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  371. for (itr = player->player_quests.begin(); itr != player->player_quests.end(); itr++) {
  372. quest = itr->second;
  373. if (quest->IsTracked()) {
  374. quest->SetTracked(false);
  375. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  376. quest->SetTracked(true);
  377. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  378. }
  379. }
  380. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  381. // SendAchievementsList();
  382. /*Guild* guild = player->GetGuild();
  383. if (guild) {
  384. guild->UpdateGuildMemberInfo(GetPlayer());
  385. if (firstlogin)
  386. guild->SendGuildMOTD(this);
  387. guild->SendGuildUpdate(this);
  388. guild->SendGuildMember(GetPlayer(), firstlogin);
  389. guild->SendGuildEventList(this);
  390. guild->SendGuildBankEventList(this);
  391. guild->SendAllGuildEvents(this);
  392. guild->SendGuildMemberList(this);
  393. }*/
  394. if (version > 373) {
  395. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Faction Updates...");
  396. EQ2Packet* outapp = player->GetFactions()->FactionUpdate(GetVersion());
  397. if (outapp) {
  398. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  399. //DumpPacket(outapp);
  400. QueuePacket(outapp);
  401. }
  402. }
  403. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Command List...");
  404. ClientPacketFunctions::SendCommandList(this);
  405. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Language Updates...");
  406. // kos doesn't like one of these language or instance list
  407. SendLanguagesUpdate(database.GetCharacterCurrentLang(GetCharacterID(), player));
  408. //ClientPacketFunctions::SendInstanceList(this);
  409. SendZoneInfo();
  410. /*Spell* spell = 0;
  411. vector<QuickBarItem*>::iterator itr;
  412. for(itr = player->GetQuickbar()->begin(); itr != player->GetQuickbar()->end(); itr++){
  413. if((*itr)->type == 1){
  414. spell = master_spell_list.GetSpell((*itr)->id);
  415. if(spell)
  416. QueuePacket(spell->serialize(this, false, 0x20));
  417. }
  418. }*/
  419. }
  420. void Client::SendPlayerDeathWindow()
  421. {
  422. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendPlayerDeathWindow");
  423. vector<RevivePoint*>* results = GetCurrentZone()->GetRevivePoints(this);
  424. vector<RevivePoint*>::iterator itr;
  425. if (results && results->size() > 0)
  426. {
  427. PacketStruct* packet = configReader.getStruct("WS_DeathWindow", GetVersion());
  428. if (packet)
  429. {
  430. packet->setArrayLengthByName("location_count", results->size());
  431. RevivePoint* point = 0;
  432. int32 i = 0;
  433. for (itr = results->begin(); itr != results->end(); itr++, i++)
  434. {
  435. point = *itr;
  436. if (point)
  437. {
  438. packet->setArrayDataByName("location_id", point->id, i);
  439. //zone_name = database.GetZoneName(point->zone_id);
  440. string zone_name = database.GetZoneDescription(point->zone_id);
  441. if (zone_name.length() > 0)
  442. packet->setArrayDataByName("zone_name", zone_name.c_str(), i);
  443. packet->setArrayDataByName("location_name", point->location_name.c_str(), i);
  444. packet->setArrayDataByName("distance", GetPlayer()->GetDistance(point->x, point->y, point->z), i);
  445. }
  446. if (point->id == 0xFFFFFFFF)//tmp location
  447. safe_delete(point);
  448. }
  449. #if EQDEBUG >= 3
  450. LogWrite(CCLIENT__DEBUG, 0, "Client", "WS_DeathWindow Packet:");
  451. packet->PrintPacket();
  452. #endif
  453. EQ2Packet* outapp = packet->serialize();
  454. QueuePacket(outapp);
  455. safe_delete(packet);
  456. }
  457. // done with the revive points so lets free up the pointer
  458. safe_delete(results);
  459. }
  460. }
  461. void Client::DisplayDeadWindow()
  462. {
  463. LogWrite(ZONE__DEBUG, 0, "Zone", "DisplayDeadWindow()");
  464. player->SetHP(0);
  465. player->SetPower(0);
  466. GetCurrentZone()->TriggerCharSheetTimer();
  467. if(GetVersion() <= 561) {
  468. ClientPacketFunctions::SendServerControlFlagsClassic(this, 8, 1);
  469. ClientPacketFunctions::SendServerControlFlagsClassic(this, 16, 1);
  470. }
  471. else {
  472. ClientPacketFunctions::SendServerControlFlags(this, 1, 8, 1);
  473. ClientPacketFunctions::SendServerControlFlags(this, 1, 16, 1);
  474. }
  475. PacketStruct* packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  476. if (packet)
  477. {
  478. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  479. QueuePacket(packet->serialize());
  480. safe_delete(packet);
  481. }
  482. SendPlayerDeathWindow();
  483. }
  484. void Client::HandlePlayerRevive(int32 point_id)
  485. {
  486. if(GetVersion() <= 561) {
  487. ClientPacketFunctions::SendServerControlFlagsClassic(this, 8, 0);
  488. ClientPacketFunctions::SendServerControlFlagsClassic(this, 16, 0);
  489. }
  490. else {
  491. ClientPacketFunctions::SendServerControlFlags(this, 1, 8, 0);
  492. ClientPacketFunctions::SendServerControlFlags(this, 1, 16, 0);
  493. }
  494. SimpleMessage(CHANNEL_NARRATIVE, "You regain consciousness!");
  495. PacketStruct* packet = configReader.getStruct("WS_Resurrected", GetVersion());
  496. if (packet)
  497. {
  498. QueuePacket(packet->serialize());
  499. safe_delete(packet);
  500. }
  501. float origX, origY, origZ, origHeading = 0.0f;
  502. origX = player->GetX();
  503. origY = player->GetY();
  504. origZ = player->GetZ();
  505. origHeading = player->GetHeading();
  506. ZoneServer* originalZone = GetCurrentZone();
  507. int32 origGridID = GetPlayer()->GetLocation();
  508. float x, y, z, heading;
  509. RevivePoint* revive_point = 0;
  510. if (point_id != 0xFFFFFFFF)
  511. revive_point = GetCurrentZone()->GetRevivePoint(point_id);
  512. string zone_desc;
  513. const char* location_name = "Unknown";
  514. player->SetAlive(true);
  515. player->SetResurrecting(true);
  516. player->SetHP(player->GetTotalHP());
  517. player->SetPower(player->GetTotalPower());
  518. //revive at zone safe coords
  519. if (!revive_point)
  520. {
  521. LogWrite(CCLIENT__WARNING, 0, "Client", "No Revive Point! Spawning player at safe coordinates!");
  522. x = GetCurrentZone()->GetSafeX();
  523. y = GetCurrentZone()->GetSafeY();
  524. z = GetCurrentZone()->GetSafeZ();
  525. heading = GetCurrentZone()->GetSafeHeading();
  526. zone_desc = GetCurrentZone()->GetZoneDescription();
  527. location_name = "Zone Safe Point";
  528. Zone(GetCurrentZone()->GetZoneName(), false);
  529. }
  530. else
  531. {
  532. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to chosen Revive Point.");
  533. x = revive_point->x;
  534. y = revive_point->y;
  535. z = revive_point->z;
  536. heading = revive_point->heading;
  537. zone_desc = database.GetZoneDescription(revive_point->zone_id);
  538. location_name = revive_point->location_name.c_str();
  539. Zone(GetCurrentZone()->GetZoneName(), false);
  540. }
  541. player->SetX(x);
  542. player->SetY(y);
  543. player->SetZ(z);
  544. player->SetHeading(heading);
  545. LogWrite(CCLIENT__DEBUG, 0, "Client", "Attempt Revive @ %s, %.2f, %.2f, %.2f, %.2f, HP: %i, Pow: %i, %s",
  546. zone_desc.c_str(),
  547. player->GetX(),
  548. player->GetY(),
  549. player->GetZ(),
  550. player->GetHeading(),
  551. player->GetHP(),
  552. player->GetPower(),
  553. location_name);
  554. //player->ClearEverything();
  555. Save();
  556. if (revive_point && revive_point->zone_id != GetCurrentZone()->GetZoneID() && revive_point->zone_id != 0)
  557. {
  558. string zone_name = database.GetZoneName(revive_point->zone_id);
  559. if (zone_name.length() == 0)
  560. {
  561. LogWrite(CCLIENT__WARNING, 0, "Client", "Unable to zone player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  562. x = GetCurrentZone()->GetSafeX();
  563. y = GetCurrentZone()->GetSafeY();
  564. z = GetCurrentZone()->GetSafeZ();
  565. heading = GetCurrentZone()->GetSafeHeading();
  566. location_name = "Zone Safe Point";
  567. }
  568. else
  569. {
  570. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  571. location_name = revive_point->location_name.c_str();
  572. //player->ClearEverything();
  573. Save();
  574. Zone(zone_name.c_str(), false);
  575. }
  576. }
  577. zone_desc = GetCurrentZone()->GetZoneDescription();
  578. Message(CHANNEL_NARRATIVE, "Reviving in %s at %s.", zone_desc.c_str(), location_name);
  579. player->SetSpawnType(4);
  580. if (version > 373) {
  581. packet = configReader.getStruct("WS_CancelMoveObjectMode", GetVersion());
  582. if (packet)
  583. {
  584. QueuePacket(packet->serialize());
  585. safe_delete(packet);
  586. }
  587. }
  588. packet = configReader.getStruct("WS_TeleportWithinZone", GetVersion());
  589. if (packet)
  590. {
  591. packet->setDataByName("x", x);
  592. packet->setDataByName("y", y);
  593. packet->setDataByName("z", z);
  594. QueuePacket(packet->serialize());
  595. safe_delete(packet);
  596. }
  597. SendControlGhost();
  598. packet = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  599. if (packet)
  600. {
  601. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  602. QueuePacket(packet->serialize());
  603. safe_delete(packet);
  604. }
  605. if(rule_manager.GetGlobalRule(R_Combat, EnableSpiritShards)->GetBool())
  606. {
  607. NPC* shard = player->InstantiateSpiritShard(origX, origY, origZ, origHeading, origGridID, originalZone);
  608. if(shard->GetSpawnScript() && strlen(shard->GetSpawnScript()) > 0)
  609. originalZone->CallSpawnScript(shard, SPAWN_SCRIPT_PRESPAWN);
  610. originalZone->RemoveSpawn(player, false, true, true, true, true);
  611. originalZone->AddSpawn(shard);
  612. if(shard->GetSpawnScript() && strlen(shard->GetSpawnScript()) > 0)
  613. originalZone->CallSpawnScript(shard, SPAWN_SCRIPT_SPAWN);
  614. }
  615. m_resurrect.writelock(__FUNCTION__, __LINE__);
  616. if (current_rez.active)
  617. current_rez.should_delete = true;
  618. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  619. }
  620. void Client::SendControlGhost(int32 send_id, int8 unknown2) {
  621. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", GetVersion());
  622. if (packet) {
  623. packet->setDataByName("spawn_id", send_id);
  624. packet->setDataByName("speed", GetPlayer()->GetSpeed());
  625. packet->setDataByName("size", 0.51);
  626. packet->setDataByName("unknown2", unknown2);
  627. packet->setDataByName("air_speed", player->GetAirSpeed());
  628. EQ2Packet* app = packet->serialize();
  629. QueuePacket(app);
  630. safe_delete(packet);
  631. }
  632. }
  633. void Client::SendCharInfo() {
  634. EQ2Packet* app;
  635. player->SetEquippedItemAppearances();
  636. ClientPacketFunctions::SendCharacterData(this);
  637. SendCharPOVGhost();
  638. SendControlGhost(player->GetIDWithPlayerSpawn(player), 255);
  639. //sending bad spawn packet?
  640. //SendAchievementsList();
  641. //if (version > 561)
  642. //ClientPacketFunctions::SendHousingList(this);
  643. ClientPacketFunctions::SendCharacterSheet(this);
  644. ClientPacketFunctions::SendTraitList(this);// moved from below
  645. ClientPacketFunctions::SendAbilities(this);
  646. ClientPacketFunctions::SendSkillBook(this);
  647. if (!IsReloadingZone() && !player->IsResurrecting() && GetVersion() >= 546) {
  648. ClientPacketFunctions::SendUpdateSpellBook(this);
  649. }
  650. else {
  651. player->SetResurrecting(false);
  652. }
  653. GetCurrentZone()->AddSpawn(player);
  654. if(IsReloadingZone() && (zoning_x || zoning_y || zoning_z)) {
  655. GetPlayer()->SetX(zoning_x);
  656. GetPlayer()->SetY(zoning_y);
  657. GetPlayer()->SetZ(zoning_z);
  658. GetPlayer()->SetHeading(zoning_h);
  659. EQ2Packet* packet = GetPlayer()->Move(zoning_x, zoning_y, zoning_z, GetVersion(), zoning_h);
  660. QueuePacket(packet);
  661. }
  662. //SendCollectionList();
  663. Guild* guild = player->GetGuild();
  664. if (guild)
  665. guild->GuildMemberLogin(this, firstlogin);
  666. app = player->GetPlayerItemList()->serialize(GetPlayer(), GetVersion());
  667. if (app) {
  668. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  669. //DumpPacket(app);
  670. QueuePacket(app);
  671. }
  672. app = player->GetEquipmentList()->serialize(GetVersion(), player);
  673. if (app) {
  674. QueuePacket(app);
  675. }
  676. app = player->GetAppearanceEquipmentList()->serialize(GetVersion(), player);
  677. if (app) {
  678. QueuePacket(app);
  679. }
  680. vector<Item*>* items = player->GetPlayerItemList()->GetItemsFromBagID(-3); // bank items
  681. if (items && items->size() > 0) {
  682. for (int32 i = 0; i < items->size(); i++) {
  683. EQ2Packet* outapp = items->at(i)->serialize(GetVersion(), false, GetPlayer());
  684. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  685. //DumpPacket(outapp);
  686. QueuePacket(outapp);
  687. }
  688. }
  689. if (firstlogin && (app = chat.GetWorldChannelList(this)) != NULL)
  690. QueuePacket(app);
  691. safe_delete(items);
  692. items = player->GetPlayerItemList()->GetItemsFromBagID(-4); //shared bank items
  693. if (items && items->size() > 0) {
  694. for (int32 i = 0; i < items->size(); i++)
  695. QueuePacket(items->at(i)->serialize(GetVersion(), false, GetPlayer()));
  696. }
  697. safe_delete(items);
  698. if (version >= 373) {
  699. SendTitleUpdate();
  700. }
  701. GetPlayer()->UpdateWeapons();
  702. if(!GetPlayer()->IsReturningFromLD()) {
  703. database.LoadBuyBacks(this);
  704. }
  705. if (version > 561)
  706. master_aa_list.DisplayAA(this, 0, 0);
  707. string zone_motd = GetCurrentZone()->GetZoneMOTD();
  708. if (zone_motd.length() > 0 && zone_motd[0] != ' ') {
  709. string zone_motd_send = "Zone MOTD: " + zone_motd;
  710. SimpleMessage(CHANNEL_NARRATIVE, zone_motd_send.c_str());
  711. }
  712. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  713. if (zone_script && lua_interface)
  714. lua_interface->RunZoneScript(zone_script, "player_entry", GetCurrentZone(), GetPlayer());
  715. this->client_zoning = false;
  716. this->zoning_id = 0;
  717. this->zoning_instance_id = 0;
  718. SetZoningDestination(nullptr);
  719. if (player->GetHP() < player->GetTotalHP() || player->GetPower() < player->GetTotalPower())
  720. GetCurrentZone()->AddDamagedSpawn(player);
  721. if (firstlogin)
  722. firstlogin = false;
  723. player->ClearProcs();
  724. items = player->GetEquippedItemList();
  725. if (items && items->size() > 0) {
  726. for (int32 i = 0; i < items->size(); i++) {
  727. Item* item = items->at(i);
  728. if (item && item->GetItemScript() && lua_interface)
  729. lua_interface->RunItemScript(item->GetItemScript(), "equipped", item, player);
  730. }
  731. }
  732. //Allow this player to change their last name if they meet the level requirement
  733. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && player->GetLevel() >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  734. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  735. safe_delete(items);
  736. if (!player->Alive())
  737. DisplayDeadWindow();
  738. ClientPacketFunctions::SendLocalizedTextMessage(this);
  739. if (GetCurrentZone()->GetInstanceID())
  740. {
  741. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(GetCurrentZone()->GetInstanceID());
  742. if (ph) {
  743. //HouseZone* hz = world.GetHouseZone(ph->house_id);
  744. string name = string(GetPlayer()->GetName());
  745. if (name.compare(ph->player_name) == 0)
  746. SetHasOwnerOrEditAccess(true);
  747. }
  748. }
  749. bool groupMentor = false;
  750. GetPlayer()->group_id = rejoin_group_id;
  751. if(!world.RejoinGroup(this, rejoin_group_id))
  752. GetPlayer()->group_id = 0;
  753. else
  754. {
  755. Entity* ent = world.GetGroupManager()->IsPlayerInGroup(rejoin_group_id, GetPlayer()->GetGroupMemberInfo()->mentor_target_char_id);
  756. if(ent && ent->IsPlayer())
  757. {
  758. GetPlayer()->SetMentorStats(ent->GetLevel(), ent->GetID(), false);
  759. groupMentor = true;
  760. }
  761. }
  762. if(!groupMentor)
  763. GetPlayer()->SetMentorStats(GetPlayer()->GetLevel(), 0, false);
  764. if(!GetPlayer()->IsReturningFromLD()) {
  765. database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_MAINTAINEDEFFECTS);
  766. database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_SPELLEFFECTS);
  767. }
  768. else {
  769. Spawn* pet_spawn = nullptr;
  770. if(GetPlayer()->GetPet())
  771. pet_spawn = GetPlayer()->GetPet();
  772. else if(GetPlayer()->GetCharmedPet())
  773. pet_spawn = GetPlayer()->GetCharmedPet();
  774. else if(GetPlayer()->GetCosmeticPet())
  775. pet_spawn = GetPlayer()->GetCosmeticPet();
  776. else if(GetPlayer()->GetDeityPet())
  777. pet_spawn = GetPlayer()->GetDeityPet();
  778. if(pet_spawn) {
  779. GetPlayer()->GetInfoStruct()->set_pet_id(GetPlayer()->GetIDWithPlayerSpawn(pet_spawn));
  780. }
  781. }
  782. GetPlayer()->SetSaveSpellEffects(false);
  783. GetPlayer()->SetCharSheetChanged(true);
  784. GetPlayer()->SetReturningFromLD(false);
  785. }
  786. void Client::SendZoneSpawns() {
  787. //Allows us to place spawns almost anywhere
  788. if (version > 373) {
  789. uchar blah[] = { 0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46 };
  790. EQ2Packet* app = new EQ2Packet(OP_MoveableObjectPlacementCriteri, blah, sizeof(blah));
  791. QueuePacket(app);
  792. }
  793. ClientPacketFunctions::SendSkillSlotMappings(this);
  794. ClientPacketFunctions::SendGameWorldTime(this);
  795. GetCurrentZone()->StartZoneInitialSpawnThread(this);
  796. }
  797. void Client::SendCharPOVGhost() {
  798. bool use_ghost_pov = false;
  799. PacketStruct* set_pov = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  800. int32 ghost_id = 0;
  801. if (set_pov) {
  802. if(pov_ghost_spawn_id) {
  803. Spawn* spawn = GetCurrentZone()->GetSpawnByID(pov_ghost_spawn_id);
  804. ghost_id = player->GetIDWithPlayerSpawn(spawn);
  805. if(spawn) {
  806. use_ghost_pov = true;
  807. }
  808. }
  809. if(use_ghost_pov) {
  810. set_pov->setDataByName("spawn_id", ghost_id);
  811. }
  812. else {
  813. set_pov->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  814. }
  815. EQ2Packet* app_pov = set_pov->serialize();
  816. QueuePacket(app_pov);
  817. safe_delete(set_pov);
  818. }
  819. }
  820. void Client::SendZoneInfo() {
  821. ZoneServer* zone = GetCurrentZone();
  822. if (zone) {
  823. EQ2Packet* packet = zone->GetZoneInfoPacket(this);
  824. QueuePacket(packet);
  825. if (version > 561) {
  826. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  827. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  828. #if EQDEBUG >= 9
  829. fog_packet->PrintPacket();
  830. #endif
  831. if (fog_packet) {
  832. database.LoadFogInit(zone->GetZoneFile(), fog_packet);
  833. QueuePacket(fog_packet->serialize());
  834. safe_delete(fog_packet);
  835. }
  836. zone->SendFlightPathsPackets(this);
  837. }
  838. }
  839. /*
  840. uchar blah[] ={0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x01,0x00,0x00,0x00,0x00
  841. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  842. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF
  843. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  844. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00
  845. ,0x00,0x00,0x00,0x00,0x10,0x49,0x2B,0x62,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  846. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  847. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  848. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  849. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  850. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  851. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  852. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  853. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  854. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  855. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  856. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  857. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  858. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  859. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  860. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  861. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  862. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  863. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  864. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  865. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  866. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  867. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  868. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  869. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  870. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  871. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  872. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  873. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  874. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  875. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00};
  876. EQ2Packet* appA = new EQ2Packet(OP_GuildUpdateMsg, blah, sizeof(blah));
  877. QueuePacket(appA);
  878. uchar blahA[] ={0x45,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00
  879. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  880. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  881. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00
  882. ,0x00,0x10,0xE2,0x10,0x6C,0x00,0x00,0x00,0x00};
  883. EQ2Packet* appB = new EQ2Packet(OP_KeymapDataMsg, blahA, sizeof(blahA));
  884. QueuePacket(appB);
  885. */
  886. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendFriendList");
  887. SendFriendList();
  888. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendIgnoreList");
  889. SendIgnoreList();
  890. }
  891. void Client::SendDefaultGroupOptions() {
  892. /*
  893. 0 - loot method
  894. 1 - loot items rarity
  895. 2 - Auto split coin
  896. 4 - default yell method
  897. 6 - group autolock
  898. 7 - solo autolock
  899. */
  900. PacketStruct* default_options = configReader.getStruct("WS_DefaultGroupOptions", GetVersion());
  901. if (default_options) {
  902. default_options->setDataByName("loot_method", GetPlayer()->GetInfoStruct()->get_group_loot_method());
  903. default_options->setDataByName("loot_items_rarity", GetPlayer()->GetInfoStruct()->get_group_loot_items_rarity());
  904. default_options->setDataByName("auto_split_coin", GetPlayer()->GetInfoStruct()->get_group_auto_split());
  905. default_options->setDataByName("default_yell_method", GetPlayer()->GetInfoStruct()->get_group_default_yell());
  906. default_options->setDataByName("group_autolock", GetPlayer()->GetInfoStruct()->get_group_autolock());
  907. default_options->setDataByName("default_group_lock_method", GetPlayer()->GetInfoStruct()->get_group_lock_method());
  908. if(GetVersion() > 561) {
  909. default_options->setDataByName("solo_autolock", GetPlayer()->GetInfoStruct()->get_group_solo_autolock());
  910. default_options->setDataByName("auto_loot_method", GetPlayer()->GetInfoStruct()->get_group_auto_loot_method());
  911. }
  912. EQ2Packet* app7 = default_options->serialize();
  913. QueuePacket(app7);
  914. safe_delete(default_options);
  915. }
  916. }
  917. bool Client::HandlePacket(EQApplicationPacket* app) {
  918. bool ret = true;
  919. //cout << "INCOMING PACKET!!!!!!!: " << app->GetOpcodeName() << endl;
  920. //DumpPacket(app);
  921. #if EQDEBUG >= 9
  922. LogWrite(PACKET__DEBUG, 9, "Packet", "[EQDEBUG] Received Packet:");
  923. DumpPacket(app, true);
  924. #endif
  925. EmuOpcode opcode = app->GetOpcode();
  926. #if EQDEBUG >= 9
  927. const char* name = app->GetOpcodeName();
  928. if (name)
  929. cout << name;
  930. else
  931. cout << "Unknown";
  932. cout << " Packet: OPCode: 0x" << hex << setw(2) << setfill('0') << app->GetOpcode() << dec << ", size: " << setw(5) << setfill(' ') << app->Size() << endl;
  933. DumpPacket(app);
  934. #endif
  935. //if (opcode != OP_UpdatePositionMsg) {
  936. // LogWrite(PACKET__DEBUG, 0, "opcode %s received", app->GetOpcodeName());
  937. //}
  938. if (!connected_to_zone && opcode != OP_LoginByNumRequestMsg)
  939. {
  940. opcode = _maxEmuOpcode; // skip since this is not a valid packet, sent before we allowed the login
  941. }
  942. switch (opcode) {
  943. case _maxEmuOpcode:
  944. break;
  945. case OP_LoginByNumRequestMsg: {
  946. LogWrite(OPCODE__DEBUG, 0, "Opcode", "Opcode 0x%X (%i): OP_LoginByNumRequestMsg", opcode, opcode);
  947. PacketStruct* request;
  948. request = configReader.getStruct("LoginByNumRequest", 1);
  949. if (request) {
  950. if(request->LoadPacketData(app->pBuffer, app->size)) {
  951. // test the original location of Version for clients older than 1212
  952. version = request->getType_int16_ByName("version");
  953. if (version == 0 || version >= 1208 || EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  954. // must be new client data version method, re-fetch the packet
  955. safe_delete(request);
  956. request = configReader.getStruct("LoginByNumRequest", 1208);
  957. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  958. // Xinux suggests using an INT16 here. Our first new version = 57000
  959. version = request->getType_int16_ByName("version");
  960. }
  961. else {
  962. LogWrite(LOGIN__ERROR, 0, "Login", "Nasty Horrible things happening. Tell a dev asap! Version: %i", version);
  963. break;
  964. }
  965. }
  966. if (EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  967. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  968. ClientPacketFunctions::SendLoginDenied(this);
  969. /* reset version and protect server from trying to send packets out to a bad client
  970. ** cause of Dec 6th/Dec 7th 2023 crash
  971. ** Client::MakeSpawnChangePacket
  972. ** int16 opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd); <-- crashes pulling opcode with bad version
  973. */
  974. version = 546;
  975. ready_for_updates = false;
  976. ready_for_spawns = false;
  977. return false;
  978. }
  979. int32 account_id = request->getType_int32_ByName("account_id");
  980. int32 access_code = request->getType_int32_ByName("access_code");
  981. if (!HandleNewLogin(account_id, access_code))
  982. return false;
  983. }
  984. }
  985. safe_delete(request);
  986. break;
  987. }
  988. case OP_DefaultGroupOptionsMsg: {
  989. PacketStruct* packet = configReader.getStruct("WS_DefaultGroupOptions", GetVersion());
  990. if (packet) {
  991. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  992. packet->PrintPacket();
  993. int8 loot_method = packet->getType_int8_ByName("loot_method");
  994. int8 loot_items_rarity = packet->getType_int8_ByName("loot_items_rarity");
  995. int8 auto_split_coin = packet->getType_int8_ByName("auto_split_coin");
  996. int8 default_yell_method = packet->getType_int8_ByName("default_yell_method");
  997. int8 autolock = packet->getType_int8_ByName("group_autolock");
  998. int8 group_lock_method = packet->getType_int8_ByName("default_group_lock_method");
  999. int8 solo_autolock = packet->getType_int8_ByName("solo_autolock");
  1000. int8 auto_loot_method = 0;
  1001. if (GetVersion() > 561) {
  1002. auto_loot_method = packet->getType_int8_ByName("auto_loot_method");
  1003. if (auto_loot_method > AutoLootMode::METHOD_DECLINE)
  1004. auto_loot_method = AutoLootMode::METHOD_DECLINE;
  1005. }
  1006. GetPlayer()->GetInfoStruct()->set_group_loot_method(loot_method);
  1007. GetPlayer()->GetInfoStruct()->set_group_loot_items_rarity(loot_items_rarity);
  1008. GetPlayer()->GetInfoStruct()->set_group_auto_split(auto_split_coin);
  1009. GetPlayer()->GetInfoStruct()->set_group_default_yell(default_yell_method);
  1010. GetPlayer()->GetInfoStruct()->set_group_autolock(autolock);
  1011. GetPlayer()->GetInfoStruct()->set_group_lock_method(group_lock_method);
  1012. GetPlayer()->GetInfoStruct()->set_group_solo_autolock(solo_autolock);
  1013. GetPlayer()->GetInfoStruct()->set_group_auto_loot_method(auto_loot_method);
  1014. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPLOOTMETHOD, (char*)std::to_string(loot_method).c_str());
  1015. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPLOOTITEMRARITY, (char*)std::to_string(loot_items_rarity).c_str());
  1016. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPAUTOSPLIT, (char*)std::to_string(auto_split_coin).c_str());
  1017. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPDEFAULTYELL, (char*)std::to_string(default_yell_method).c_str());
  1018. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPAUTOLOCK, (char*)std::to_string(autolock).c_str());
  1019. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPLOCKMETHOD, (char*)std::to_string(group_lock_method).c_str());
  1020. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPSOLOAUTOLOCK, (char*)std::to_string(solo_autolock).c_str());
  1021. database.insertCharacterProperty(this, CHAR_PROPERTY_AUTOLOOTMETHOD, (char*)std::to_string(auto_loot_method).c_str());
  1022. if (this->GetPlayer()->GetGroupMemberInfo() && this->GetPlayer()->GetGroupMemberInfo()->leader)
  1023. {
  1024. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  1025. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  1026. if (group)
  1027. {
  1028. GroupOptions goptions;
  1029. goptions.loot_method = loot_method;
  1030. goptions.loot_items_rarity = loot_items_rarity;
  1031. goptions.auto_split = auto_split_coin;
  1032. goptions.default_yell = default_yell_method;
  1033. goptions.group_autolock = autolock;
  1034. goptions.solo_autolock = solo_autolock;
  1035. goptions.auto_loot_method = auto_loot_method;
  1036. group->SetDefaultGroupOptions(&goptions);
  1037. }
  1038. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  1039. }
  1040. }
  1041. safe_delete(packet);
  1042. }
  1043. break;
  1044. }
  1045. case OP_MapRequest: {
  1046. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapRequest", opcode, opcode);
  1047. PacketStruct* packet = configReader.getStruct("WS_MapRequest", GetVersion());
  1048. if (packet && app->size > 2 && GetCurrentZone()) {
  1049. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1050. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  1051. if (fog_packet) {
  1052. LogWrite(PACKET__DEBUG, 0, "Packet", "In OP_MapRequest: Fog Packet");
  1053. database.LoadFogInit(packet->getType_EQ2_16BitString_ByName("zone").data, fog_packet);
  1054. fog_packet->setDataByName("unknown1", 1);
  1055. fog_packet->setDataByName("unknown3", 1);
  1056. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1057. //fog_packet->PrintPacket();
  1058. QueuePacket(fog_packet->serialize());
  1059. safe_delete(fog_packet);
  1060. }
  1061. }
  1062. safe_delete(packet);
  1063. }
  1064. break;
  1065. }
  1066. case OP_RequestCampMsg: {
  1067. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RequestCampMsg", opcode, opcode);
  1068. PacketStruct* request = configReader.getStruct("WS_RequestCamp", GetVersion());
  1069. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  1070. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client '%s' (%u) is camping...", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  1071. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_RequestCamp - quit: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  1072. request->getType_int8_ByName("quit"),
  1073. request->getType_int8_ByName("camp_desktop"),
  1074. request->getType_int16_ByName("camp_char_select"),
  1075. (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? request->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  1076. //DumpPacket(app->pBuffer, app->size);
  1077. //request->PrintPacket();
  1078. if (!camp_timer) {
  1079. int16 camp_time = 20; // default if rule cannot be found
  1080. if (GetAdminStatus() >= 100)
  1081. camp_time = rule_manager.GetGlobalRule(R_World, GMCampTimer)->GetInt16();
  1082. else
  1083. camp_time = rule_manager.GetGlobalRule(R_World, PlayerCampTimer)->GetInt16();
  1084. PacketStruct* response = configReader.getStruct("WS_Camp", GetVersion());
  1085. if (response) {
  1086. bool disconnect = false;
  1087. if (request->getType_int8_ByName("camp_desktop") == 1 && request->getType_int8_ByName("quit") == 1) {
  1088. // Command: /camp desktop
  1089. // Command: /quit
  1090. response->setDataByName("camp_desktop", 1);
  1091. disconnect = true;
  1092. }
  1093. else {
  1094. // Command: /camp
  1095. response->setDataByName("camp_desktop", request->getType_int8_ByName("camp_desktop"));
  1096. response->setDataByName("camp_char_select", request->getType_int16_ByName("camp_char_select"));
  1097. response->setDataByName("seconds", camp_time);
  1098. }
  1099. camp_timer = new Timer(camp_time * 1000);
  1100. camp_timer->Enable();
  1101. if (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) {
  1102. // /camp {char_name}
  1103. response->setDataByName("char_name", request->getType_EQ2_16BitString_ByName("char_name").data.c_str());
  1104. }
  1105. else if (request->getType_int8_ByName("camp_desktop") == 0 && request->getType_int16_ByName("camp_char_select") == 0) {
  1106. // /camp (go back to char selection screen)
  1107. response->setDataByName("char_name", " ");
  1108. response->setDataByName("camp_char_select", 1);
  1109. }
  1110. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_Camp - seconds: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  1111. response->getType_int8_ByName("seconds"),
  1112. response->getType_int8_ByName("camp_desktop"),
  1113. response->getType_int8_ByName("camp_char_select"),
  1114. (response->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? response->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  1115. // JA: trying to recognize /camp vs LD (see ZoneServer::ClientProcess())
  1116. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0)
  1117. player->SetActivityStatus(player->GetActivityStatus() + ACTIVITY_STATUS_CAMPING);
  1118. //response->PrintPacket();
  1119. QueuePacket(response->serialize());
  1120. safe_delete(response);
  1121. if (disconnect)
  1122. Disconnect();
  1123. }
  1124. }
  1125. }
  1126. safe_delete(request);
  1127. break;
  1128. }
  1129. case OP_StoodMsg: {
  1130. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StoodMsg", opcode, opcode);
  1131. if (camp_timer)
  1132. {
  1133. // JA: clear camping flag
  1134. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1135. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1136. safe_delete(camp_timer);
  1137. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1138. QueuePacket(outapp);
  1139. }
  1140. player->SetTempVisualState(0);
  1141. break;
  1142. }
  1143. case OP_StandMsg: {
  1144. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StandMsg", opcode, opcode);
  1145. if (camp_timer)
  1146. {
  1147. // JA: clear camping flag
  1148. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1149. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1150. safe_delete(camp_timer);
  1151. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1152. QueuePacket(outapp);
  1153. }
  1154. player->SetTempVisualState(539);
  1155. break;
  1156. }
  1157. case OP_SitMsg: {
  1158. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SitMsg", opcode, opcode);
  1159. player->SetTempVisualState(538);
  1160. break;
  1161. }
  1162. case OP_SatMsg: {
  1163. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SatMsg", opcode, opcode);
  1164. player->SetTempVisualState(540);
  1165. break;
  1166. }
  1167. case OP_QuestJournalOpenMsg:
  1168. case OP_QuestJournalInspectMsg: {
  1169. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalOpenMsg, OP_QuestJournalInspectMsg", opcode, opcode);
  1170. if (app->size < sizeof(int32))
  1171. break;
  1172. int32 quest_id = 0;
  1173. memcpy(&quest_id, app->pBuffer, sizeof(int32));
  1174. GetPlayer()->SendQuest(quest_id);
  1175. break;
  1176. }
  1177. case OP_QuestJournalSetVisibleMsg: {
  1178. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalSetVisibleMsg", opcode, opcode);
  1179. PacketStruct* packet = configReader.getStruct("WS_QuestJournalVisible", GetVersion());
  1180. if (packet) {
  1181. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1182. int32 quest_id = packet->getType_int32_ByName("quest_id");
  1183. bool hidden = packet->getType_int8_ByName("visible") == 1 ? false : true;
  1184. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  1185. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  1186. if (player_quests) {
  1187. if (player_quests->count(quest_id) > 0)
  1188. player_quests->at(quest_id)->SetHidden(hidden);
  1189. else
  1190. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Player does not have quest with id of %u", quest_id);
  1191. }
  1192. else
  1193. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Unable to get player(%s) quests", player->GetName());
  1194. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  1195. }
  1196. safe_delete(packet);
  1197. }
  1198. break;
  1199. }
  1200. case OP_MacroUpdateMsg: {
  1201. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MacroUpdateMsg", opcode, opcode);
  1202. PacketStruct* macro_update = configReader.getStruct("WS_MacroUpdate", GetVersion());
  1203. if (macro_update) {
  1204. if(macro_update->LoadPacketData(app->pBuffer, app->size)) {
  1205. vector<string>* update = new vector<string>;
  1206. int8 number = macro_update->getType_int8_ByName("number");
  1207. int16 icon = macro_update->getType_int16_ByName("icon");
  1208. string name = macro_update->getType_EQ2_8BitString_ByName("name").data;
  1209. int8 count = macro_update->getType_int8_ByName("macro_count");
  1210. if (GetVersion() <= 373) {
  1211. update->push_back(macro_update->getType_EQ2_8BitString_ByName("command").data);
  1212. }
  1213. else {
  1214. for (int8 i = 0; i < count; i++) {
  1215. char tmp_command[15] = { 0 };
  1216. sprintf(tmp_command, "command_%i", i);
  1217. update->push_back(macro_update->getType_EQ2_16BitString_ByName(tmp_command).data);
  1218. }
  1219. }
  1220. if (name.length() == 0)
  1221. database.UpdateCharacterMacro(GetCharacterID(), number, 0, icon, update);
  1222. else
  1223. database.UpdateCharacterMacro(GetCharacterID(), number, name.c_str(), icon, update);
  1224. safe_delete(update);
  1225. }
  1226. safe_delete(macro_update);
  1227. }
  1228. break;
  1229. }
  1230. case OP_DialogSelectMsg: {
  1231. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DialogSelectMsg", opcode, opcode);
  1232. PacketStruct* packet = configReader.getStruct("WS_DialogSelect", GetVersion());
  1233. if (packet) {
  1234. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1235. int32 conversation_id = packet->getType_int32_ByName("conversation_id");
  1236. int32 response_index = packet->getType_int32_ByName("response");
  1237. HandleDialogSelectMsg(conversation_id, response_index);
  1238. }
  1239. }
  1240. safe_delete(packet);
  1241. break;
  1242. }
  1243. case OP_CancelMoveObjectModeMsg: {
  1244. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1245. if (GetTempPlacementSpawn())
  1246. {
  1247. Spawn* tmp = GetTempPlacementSpawn();
  1248. SetTempPlacementSpawn(nullptr);
  1249. SetPlacementUniqueItemID(0);
  1250. GetCurrentZone()->RemoveSpawn(tmp, true, false, true, true, true);
  1251. break; // break out early if we are tied to a temp spawn
  1252. }
  1253. // if we are moving some other object? other use-cases not covered
  1254. break;
  1255. }
  1256. case OP_PositionMoveableObject: {
  1257. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PositionMoveableObject", opcode, opcode);
  1258. PacketStruct* place_object = configReader.getStruct("WS_PlaceMoveableObject", GetVersion());
  1259. if (place_object && place_object->LoadPacketData(app->pBuffer, app->size)) {
  1260. Spawn* spawn = 0;
  1261. if (GetTempPlacementSpawn())
  1262. spawn = GetTempPlacementSpawn();
  1263. else
  1264. spawn = GetPlayer()->GetSpawnWithPlayerID(place_object->getType_int32_ByName("spawn_id"));
  1265. if (!spawn) {
  1266. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn.");
  1267. break;
  1268. }
  1269. else if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE && !HasOwnerOrEditAccess())
  1270. {
  1271. SimpleMessage(CHANNEL_COLOR_RED, "This is not your home!");
  1272. break;
  1273. }
  1274. int32 uniqueID = spawn->GetPickupUniqueItemID();
  1275. if(uniqueID) {
  1276. Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  1277. if(uniqueItem && uniqueItem->CheckFlag2(HOUSE_LORE) && GetCurrentZone()->HouseItemSpawnExists(uniqueItem->details.item_id)) {
  1278. Message(CHANNEL_COLOR_RED, "Item %s is house lore and you cannot place another.", uniqueItem->name.c_str());
  1279. break;
  1280. }
  1281. }
  1282. // handles instantiation logic + adding to zone of a new house object
  1283. PopulateHouseSpawn(place_object);
  1284. float newHeading = place_object->getType_float_ByName("heading") + 180;
  1285. char query[256];
  1286. switch (GetSpawnPlacementMode())
  1287. {
  1288. case ServerSpawnPlacementMode::OPEN_HEADING:
  1289. {
  1290. if (spawn && spawn->IsWidget())
  1291. {
  1292. Widget* widget = (Widget*)spawn;
  1293. widget->SetOpenHeading(newHeading);
  1294. widget->SetIncludeHeading(true);
  1295. spawn->position_changed = true;
  1296. _snprintf(query, 256, "open_heading=%f,include_heading=1", newHeading);
  1297. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1298. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget open heading information.");
  1299. }
  1300. else
  1301. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1302. break;
  1303. }
  1304. case ServerSpawnPlacementMode::CLOSE_HEADING:
  1305. {
  1306. if (spawn && spawn->IsWidget())
  1307. {
  1308. Widget* widget = (Widget*)spawn;
  1309. widget->SetClosedHeading(newHeading);
  1310. widget->SetIncludeHeading(true);
  1311. spawn->position_changed = true;
  1312. _snprintf(query, 256, "closed_heading=%f,include_heading=1", newHeading);
  1313. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1314. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget close heading information.");
  1315. if (spawn->GetSpawnLocationID())
  1316. {
  1317. Query query;
  1318. query.RunQuery2(Q_INSERT, "update spawn_location_placement set heading = %f where id = %u", newHeading, spawn->GetSpawnLocationID());
  1319. }
  1320. }
  1321. else
  1322. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1323. break;
  1324. }
  1325. default:
  1326. {
  1327. spawn->SetX(place_object->getType_float_ByName("x"));
  1328. spawn->SetY(place_object->getType_float_ByName("y"));
  1329. spawn->SetZ(place_object->getType_float_ByName("z"));
  1330. spawn->SetHeading(newHeading);
  1331. spawn->SetSpawnOrigX(spawn->GetX());
  1332. spawn->SetSpawnOrigY(spawn->GetY());
  1333. spawn->SetSpawnOrigZ(spawn->GetZ());
  1334. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1335. if (spawn->GetSpawnLocationID() > 0 && database.UpdateSpawnLocationSpawns(spawn))
  1336. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved spawn information.");
  1337. else if (spawn->GetSpawnLocationID() > 0)
  1338. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn information, see console window for details.");
  1339. }
  1340. }
  1341. PopulateHouseSpawnFinalize();
  1342. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1343. }
  1344. safe_delete(place_object);
  1345. break;
  1346. }
  1347. case OP_CampAbortedMsg: {
  1348. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CampAbortedMsg", opcode, opcode);
  1349. if (camp_timer)
  1350. {
  1351. // JA: clear camping flag
  1352. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1353. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1354. safe_delete(camp_timer);
  1355. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1356. QueuePacket(outapp);
  1357. }
  1358. break;
  1359. }
  1360. case OP_DoneLoadingUIResourcesMsg: {
  1361. if(GetVersion() <= 561) {
  1362. ClientPacketFunctions::SendUpdateSpellBook(this);
  1363. }
  1364. // need to quickly flash the DoF client the rest of their inventory
  1365. if(GetVersion() <= 561) {
  1366. EQ2Packet* item_app = player->GetPlayerItemList()->serialize(GetPlayer(), GetVersion());
  1367. if (item_app) {
  1368. QueuePacket(item_app);
  1369. }
  1370. }
  1371. EQ2Packet* app = new EQ2Packet(OP_DoneLoadingUIResourcesMsg, 0, 0);
  1372. QueuePacket(app);
  1373. if(!player_loading_complete)
  1374. {
  1375. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  1376. if (zone_script && lua_interface)
  1377. lua_interface->RunZoneScript(zone_script, "player_loadcomplete", GetCurrentZone(), GetPlayer());
  1378. player_loading_complete = true;
  1379. }
  1380. break;
  1381. }
  1382. case OP_DoneLoadingZoneResourcesMsg: {
  1383. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingZoneResourcesMsg", opcode, opcode);
  1384. SendZoneSpawns();
  1385. break;
  1386. }
  1387. case OP_DefaultGroupOptionsRequestMsg: {
  1388. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DefaultGroupOptionsRequestMsg", opcode, opcode);
  1389. SendDefaultGroupOptions();
  1390. break;
  1391. }
  1392. case OP_DoneLoadingEntityResourcesMsg: {
  1393. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingEntityResourcesMsg", opcode, opcode);
  1394. if (!IsReadyForSpawns())
  1395. SetReadyForSpawns(true);
  1396. player->CalculateApplyWeight();
  1397. SendCharInfo();
  1398. GetPlayer()->GetZone()->GetSpellProcess()->SendSpellBookUpdate(this);
  1399. pos_update.Start();
  1400. quest_pos_timer.Start();
  1401. break;
  1402. }
  1403. case OP_LootItemsRequestMsg: {
  1404. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_LootItemsRequestMsg", opcode, opcode);
  1405. HandleLootItemRequestPacket(app);
  1406. break;
  1407. }
  1408. case OP_StoppedLootingMsg: {
  1409. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StoppedLootingMsg", opcode, opcode);
  1410. if (app->size < sizeof(int32))
  1411. break;
  1412. int32 loot_id = 0;
  1413. memcpy(&loot_id, app->pBuffer, sizeof(int32));
  1414. Spawn* spawn = GetCurrentZone()->GetSpawnByID(loot_id);
  1415. if(spawn) {
  1416. spawn->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
  1417. spawn->SetLooterSpawnID(0);
  1418. }
  1419. break;
  1420. }
  1421. case OP_WaypointSelectMsg: {
  1422. PacketStruct* packet = configReader.getStruct("WS_WaypointSelect", GetVersion());
  1423. if (packet) {
  1424. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1425. int32 selection = packet->getType_int32_ByName("selection");
  1426. if (selection > 0) {
  1427. SelectWaypoint(selection);
  1428. }
  1429. }
  1430. }
  1431. safe_delete(packet);
  1432. break;
  1433. }
  1434. case OP_KnowledgeWindowSlotMappingMsg: {
  1435. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_KnowledgeWindowSlotMappingMsg", opcode, opcode);
  1436. PacketStruct* packet = configReader.getStruct("WS_SpellSlotMapping", GetVersion());
  1437. if (packet) {
  1438. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1439. int num_updates = packet->getType_int16_ByName("spell_count");
  1440. int32 spell_id = 0;
  1441. int16 slot_id = 0;
  1442. char tmp_spell_id[15];
  1443. char tmp_slot[15];
  1444. for (int i = 0; i < num_updates; i++) {
  1445. memset(tmp_spell_id, 0, 15);
  1446. memset(tmp_slot, 0, 15);
  1447. sprintf(tmp_spell_id, "spell_id_%i", i);
  1448. sprintf(tmp_slot, "slot_id_%i", i);
  1449. spell_id = packet->getType_int32_ByName(tmp_spell_id);
  1450. if (spell_id > 0) {
  1451. slot_id = packet->getType_int16_ByName(tmp_slot);
  1452. SpellBookEntry* spell = player->GetSpellBookSpell(spell_id);
  1453. if (spell && spell->slot != slot_id) {
  1454. spell->slot = slot_id;
  1455. spell->save_needed = true;
  1456. }
  1457. }
  1458. }
  1459. }
  1460. safe_delete(packet);
  1461. }
  1462. //SendKnowledgeWindowSlot();
  1463. break;
  1464. }
  1465. case OP_ReadyToZoneMsg: {
  1466. if (!IsReadyForSpawns())
  1467. {
  1468. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s is logging into zone, skipping disconnect.");
  1469. }
  1470. else
  1471. {
  1472. if(zoning_destination) {
  1473. SetCurrentZone(zoning_destination);
  1474. }
  1475. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyToZoneMsg", opcode, opcode);
  1476. bool succeed_override_zone = true;
  1477. if(!GetCurrentZone()) {
  1478. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone and zone is not there! Emergency boot!", player->GetName());
  1479. if(zoning_instance_id) {
  1480. ZoneServer* zone = zone_list.GetByInstanceID(zoning_instance_id, zoning_id, true);
  1481. if(!zone) {
  1482. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Emergency boot failed for %s, unable to get zoneserver instance id %u zone id %u.", player->GetName(), zoning_instance_id, zoning_id);
  1483. succeed_override_zone = false;
  1484. }
  1485. else {
  1486. SetCurrentZone(zone);
  1487. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Unique instance has been created for %s through emergency boot!", player->GetName());
  1488. }
  1489. }
  1490. else if(zoning_id) {
  1491. ZoneServer* zone = zone_list.Get(zoning_id, true, true);
  1492. if(!zone) {
  1493. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Emergency boot failed for %s, unable to get zoneserver zone id %u.", player->GetName(), zoning_id);
  1494. succeed_override_zone = false;
  1495. }
  1496. else {
  1497. SetCurrentZone(zone);
  1498. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Unique zone has been created for %s through emergency boot!", player->GetName());
  1499. }
  1500. }
  1501. }
  1502. if (client_zoning)
  1503. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s zoning to %s", player->GetName(), GetCurrentZone()->GetZoneName());
  1504. else
  1505. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone without server authorization.", player->GetName());
  1506. Disconnect();
  1507. }
  1508. break;
  1509. }
  1510. case OP_ClientFellMsg: {
  1511. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ClientFellMsg (ouch!)", opcode, opcode);
  1512. PacketStruct* request = configReader.getStruct("WS_ClientFell", GetVersion());
  1513. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  1514. float height = request->getType_float_ByName("height");
  1515. /*int32 spawn_id = request->getType_int32_ByName("spawn_id");
  1516. if(GetPlayer()->GetSpawnWithPlayerID(spawn_id) != GetPlayer()){
  1517. cout << "Error: " << GetPlayer()->GetName() << " called ClientFell with an invalid ID of: " << spawn_id << endl;
  1518. break;
  1519. }*/
  1520. float safe_height = 13.0f;
  1521. float safe_skill_with_bonus = GetPlayer()->CalculateSkillWithBonus("Safe Fall", ITEM_STAT_SAFE_FALL, true);
  1522. if (safe_skill_with_bonus > 0.0f)
  1523. safe_height += (1 + safe_skill_with_bonus) / 5;
  1524. if (height > safe_height) {
  1525. int16 damage = (int16)ceil((height - safe_height) * 125);
  1526. if (height >= 80)
  1527. damage = 30000;
  1528. //cout << "Detected fall height:" << height << " damage:" << damage << endl;
  1529. if (damage > 0) {
  1530. GetPlayer()->TakeDamage(damage);
  1531. if (GetPlayer()->GetPlayerStatisticValue(STAT_PLAYER_HIGHEST_FALLING_HIT) < damage)
  1532. GetPlayer()->UpdatePlayerStatistic(STAT_PLAYER_HIGHEST_FALLING_HIT, damage, true);
  1533. if (!GetPlayer()->GetInvulnerable())
  1534. GetPlayer()->SetCharSheetChanged(true);
  1535. GetCurrentZone()->SendDamagePacket(0, GetPlayer(), DAMAGE_PACKET_TYPE_SIMPLE_DAMAGE, GetPlayer()->GetInvulnerable() ? DAMAGE_PACKET_RESULT_INVULNERABLE : DAMAGE_PACKET_RESULT_SUCCESSFUL, DAMAGE_PACKET_DAMAGE_TYPE_FALLING, damage, 0);
  1536. if (GetPlayer()->GetHP() == 0) {
  1537. GetCurrentZone()->KillSpawn(false, GetPlayer(), 0);
  1538. }
  1539. }
  1540. }
  1541. }
  1542. safe_delete(request);
  1543. break;
  1544. }
  1545. case OP_MapFogDataUpdateMsg: {
  1546. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapFogDataUpdateMsg", opcode, opcode);
  1547. LogWrite(MISC__TODO, 3, "TODO", "Handle (OP_MapFogDataUpdateMsg), ignoring it for now\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1548. break;
  1549. }
  1550. case OP_SelectZoneTeleporterDestinatio: {
  1551. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SelectZoneTeleporterDestinatio", opcode, opcode);
  1552. ProcessTeleportLocation(app);
  1553. break;
  1554. }
  1555. case OP_SendLatestRequestMsg: {
  1556. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SendLatestRequestMsg", opcode, opcode);
  1557. if(GetVersion() < 60085) {
  1558. // this does not exist in newer clients like AoM, confirmed to exist in DoF, other clients will need review at a later time
  1559. uchar blah25[] = { 0x01 };
  1560. EQ2Packet* app25 = new EQ2Packet(OP_ClearDataMsg, blah25, sizeof(blah25));
  1561. QueuePacket(app25);
  1562. }
  1563. break;
  1564. }
  1565. case OP_RequestRecipeDetailsMsg: {
  1566. PacketStruct* packet = configReader.getStruct("WS_RequestRecipeDetail", GetVersion());
  1567. if (packet) {
  1568. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1569. vector<int32> recipes;
  1570. int32 recipe_id = 0;
  1571. char recipe_prop_name[30];
  1572. int32 num_recipes = packet->getType_int32_ByName("num_recipes");
  1573. // WS_RecipeDetails
  1574. for (int32 i = 0; i < num_recipes; i++) {
  1575. memset(recipe_prop_name, 0, 30);
  1576. snprintf(recipe_prop_name, 30, "recipe_id_%i", i);
  1577. recipe_id = packet->getType_int32_ByName(recipe_prop_name);
  1578. if(recipe_id > 0) {
  1579. recipes.push_back(recipe_id);
  1580. }
  1581. }
  1582. SendRecipeDetails(&recipes);
  1583. }
  1584. safe_delete(packet);
  1585. }
  1586. break;
  1587. }
  1588. case OP_ShowCreateFromRecipeUIMsg: {
  1589. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ShowCreateFromRecipeUIMsg", opcode, opcode);
  1590. break;
  1591. /*uchar blah[] ={0x09,0x0e,0x00,0x51,0x75,0x65,0x65,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e
  1592. ,0x79,0x00,0x00,0x00,0x00,0x40,0x40,0xff,0xff,0xff};
  1593. EQ2Packet* app = new EQ2Packet(OP_EncounterBrokenMsg, blah, sizeof(blah));
  1594. QueuePacket(app);
  1595. uchar blah2[] = {0x00,0x00,0xff,0xff,0xff,0xff};
  1596. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah2, sizeof(blah2));
  1597. QueuePacket(app);
  1598. uchar blah3[] ={0x09,0x17,0x00,0x5c,0x23,0x46,0x46,0x45,0x34,0x30,0x30,0x20,0x51,0x75,0x65,0x65
  1599. ,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e,0x79,0x00,0x00,0x00,0x00,0xa0,0x40
  1600. ,0xff,0xff,0xff};
  1601. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah3, sizeof(blah3));
  1602. QueuePacket(app);
  1603. uchar blah4[] ={0x0b,0x00,0x21,0x00,0x00,0x00,0x1d,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17
  1604. ,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81
  1605. ,0x42,0x17,0x81,0x42,0x17,0x81,0x42};
  1606. app = new EQ2Packet(OP_UpdateSpellBookMsg, blah4, sizeof(blah4));
  1607. QueuePacket(app);
  1608. uchar blah5[] ={0x00,0x00};
  1609. app = new EQ2Packet(OP_RecipeDetailsMsg, blah5, sizeof(blah5));
  1610. QueuePacket(app);
  1611. break;*/
  1612. //player->GetPlayerInfo()->GetInfo()->cur_power = 100;
  1613. //EQ2Packet* app = player->GetPlayerInfo()->serialize(1);
  1614. //QueuePacket(app);
  1615. }
  1616. case OP_BeginItemCreationMsg: {
  1617. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginItemCreationMsg", opcode, opcode);
  1618. //DumpPacket(app->pBuffer, app->size);
  1619. PacketStruct* packet = configReader.getStruct("WS_BeginItemCreation", GetVersion());
  1620. if (packet) {
  1621. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1622. int32 item = 0;
  1623. int8 qty = 0;
  1624. vector<pair<int32, int16>> items;
  1625. char tmp_item_id[30];
  1626. int8 num_primary_selected_items = packet->getType_int8_ByName("num_primary_selected_items");
  1627. for (int8 i = 0; i < num_primary_selected_items; i++) {
  1628. memset(tmp_item_id, 0, 30);
  1629. sprintf(tmp_item_id, "primary_selected_item_id_%i", i);
  1630. item = packet->getType_int32_ByName(tmp_item_id);
  1631. sprintf(tmp_item_id, "primary_selected_item_qty_%i", i);
  1632. qty = packet->getType_int16_ByName(tmp_item_id);
  1633. if (item > 0)
  1634. items.push_back(make_pair(item,qty));
  1635. item = 0;
  1636. }
  1637. int8 build_components = packet->getType_int8_ByName("num_build_components");
  1638. for (int8 i = 0; i < build_components; i++) {
  1639. memset(tmp_item_id, 0, 30);
  1640. sprintf(tmp_item_id, "num_selected_items_%i", i);
  1641. int8 num_selected_items = packet->getType_int8_ByName(tmp_item_id);
  1642. for (int8 j = 0; j < num_selected_items; j++) {
  1643. memset(tmp_item_id, 0, 30);
  1644. sprintf(tmp_item_id, "selected_id%i_%i", i,j);
  1645. item = packet->getType_int32_ByName(tmp_item_id);
  1646. sprintf(tmp_item_id, "selected_qty%i_%i", i, j);
  1647. qty = packet->getType_int16_ByName(tmp_item_id);
  1648. if (item > 0)
  1649. items.push_back(make_pair(item, qty));
  1650. item = 0;
  1651. }
  1652. }
  1653. int8 num_fuel_items = packet->getType_int8_ByName("num_fuel_items");
  1654. for (int8 i = 0; i < num_fuel_items; i++) {
  1655. memset(tmp_item_id, 0, 30);
  1656. sprintf(tmp_item_id, "fuel_id_%i", i);
  1657. item = packet->getType_int32_ByName(tmp_item_id);
  1658. sprintf(tmp_item_id, "fuel_qty_%i", i);
  1659. qty = packet->getType_int16_ByName(tmp_item_id);
  1660. if (item > 0)
  1661. items.push_back(make_pair(item, qty));
  1662. item = 0;
  1663. }
  1664. GetCurrentZone()->GetTradeskillMgr()->BeginCrafting(this, items);
  1665. }
  1666. safe_delete(packet);
  1667. }
  1668. break;
  1669. }
  1670. case OP_StopItemCreationMsg: {
  1671. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopItemCreationMsg", opcode, opcode);
  1672. //DumpPacket(app->pBuffer, app->size);
  1673. GetCurrentZone()->GetTradeskillMgr()->StopCrafting(this);
  1674. break;
  1675. }
  1676. case OP_SysClient:
  1677. case OP_SignalMsg: {
  1678. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SysClient/OP_SignalMsg", opcode, opcode);
  1679. PacketStruct* packet = configReader.getStruct("WS_Signal", 1);
  1680. if (packet) {
  1681. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1682. EQ2_16BitString str = packet->getType_EQ2_16BitString_ByName("signal");
  1683. if (strcmp(str.data.c_str(), "sys_client_avatar_ready") == 0) {
  1684. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client '%s' (%u) is ready for spawn updates.", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  1685. SetReloadingZone(false);
  1686. if(GetPlayer()->IsDeletedSpawn()) {
  1687. GetPlayer()->SetDeletedSpawn(false);
  1688. }
  1689. ResetZoningCoords();
  1690. SetReadyForUpdates();
  1691. GetPlayer()->SendSpawnChanges(true);
  1692. ProcessStateCommands();
  1693. GetPlayer()->changed = true;
  1694. GetPlayer()->info_changed = true;
  1695. GetPlayer()->vis_changed = true;
  1696. player_pos_changed = true;
  1697. GetPlayer()->AddChangedZoneSpawn();
  1698. ProcessZoneIgnoreWidgets();
  1699. if (version <= 561) {
  1700. master_trait_list.ChooseNextTrait(this);
  1701. }
  1702. if (GetPlayer()->GetHP() < GetPlayer()->GetTotalHP() || GetPlayer()->GetPower() < GetPlayer()->GetTotalPower())
  1703. GetCurrentZone()->AddDamagedSpawn(GetPlayer());
  1704. }
  1705. else {
  1706. LogWrite(CCLIENT__WARNING, 0, "Client", "Player %s reported SysClient/SignalMsg state %s.", GetPlayer()->GetName(), str.data.c_str());
  1707. }
  1708. const char* zone_script = world.GetZoneScript(player->GetZone()->GetZoneID());
  1709. if (zone_script && lua_interface)
  1710. {
  1711. lua_interface->RunZoneScript(zone_script, "signal_changed", player->GetZone(), player, 0, str.data.c_str());
  1712. }
  1713. }
  1714. safe_delete(packet);
  1715. }
  1716. break;
  1717. }
  1718. case OP_EntityVerbsRequestMsg: {
  1719. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsRequestMsg", opcode, opcode);
  1720. HandleVerbRequest(app);
  1721. break;
  1722. }
  1723. case OP_EntityVerbsVerbMsg: {
  1724. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsVerbMsg", opcode, opcode);
  1725. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsVerb", GetVersion());
  1726. if (packet) {
  1727. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1728. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1729. player->SetTarget(player->GetSpawnWithPlayerID(spawn_id));
  1730. Spawn* spawn = player->GetTarget();
  1731. if (spawn && !spawn->IsNPC() && !spawn->IsPlayer()) {
  1732. string command = packet->getType_EQ2_16BitString_ByName("command").data;
  1733. if (!HandleHouseEntityCommands(spawn, spawn_id, command))
  1734. {
  1735. if (EntityCommandPrecheck(spawn, command.c_str())) {
  1736. if (spawn->IsGroundSpawn())
  1737. ((GroundSpawn*)spawn)->HandleUse(this, command);
  1738. else if (spawn->IsObject())
  1739. ((Object*)spawn)->HandleUse(this, command);
  1740. else if (spawn->IsWidget())
  1741. ((Widget*)spawn)->HandleUse(this, command);
  1742. else if (spawn->IsSign())
  1743. ((Sign*)spawn)->HandleUse(this, command);
  1744. }
  1745. }
  1746. }
  1747. else {
  1748. EQ2_16BitString command = packet->getType_EQ2_16BitString_ByName("command");
  1749. if (command.size > 0) {
  1750. string command_name = command.data;
  1751. if (command_name.find(" ") < 0xFFFFFFFF) {
  1752. if (GetVersion() <= 561) { //this version uses commands in the form "Buy From Merchant" instead of buy_from_merchant
  1753. string::size_type pos = command_name.find(" ");
  1754. while(pos != string::npos){
  1755. command_name.replace(pos, 1, "_");
  1756. pos = command_name.find(" ");
  1757. }
  1758. }
  1759. else
  1760. command_name = command_name.substr(0, command_name.find(" "));
  1761. }
  1762. int32 handler = commands.GetCommandHandler(command_name.c_str());
  1763. if (handler != 0xFFFFFFFF) {
  1764. if (command.data == command_name) {
  1765. command.data = "";
  1766. command.size = 0;
  1767. }
  1768. else {
  1769. command.data = command.data.substr(command.data.find(" ") + 1);
  1770. command.size = command.data.length();
  1771. }
  1772. commands.Process(handler, &command, this);
  1773. }
  1774. else {
  1775. if (spawn && spawn->IsNPC()) {
  1776. if (EntityCommandPrecheck(spawn, command.data.c_str())) {
  1777. if (!((NPC*)spawn)->HandleUse(this, command.data)) {
  1778. command_name = command.data;
  1779. string::size_type pos = command_name.find(" ");
  1780. while (pos != string::npos) {
  1781. command_name.replace(pos, 1, "_");
  1782. pos = command_name.find(" ");
  1783. }
  1784. if (!((NPC*)spawn)->HandleUse(this, command_name)) { //convert the spaces to underscores and see if that makes a difference
  1785. LogWrite(WORLD__ERROR, 0, "World", "Unhandled command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1786. }
  1787. }
  1788. }
  1789. }
  1790. else
  1791. LogWrite(WORLD__ERROR, 0, "World", "Unknown command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1792. }
  1793. }
  1794. }
  1795. }
  1796. safe_delete(packet);
  1797. }
  1798. break;
  1799. }
  1800. case OP_SkillInfoRequest: {
  1801. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SkillInfoRequest", opcode, opcode);
  1802. HandleSkillInfoRequest(app);
  1803. break;
  1804. }
  1805. case OP_UpdateTargetMsg: {
  1806. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_UpdateTargetMsg", opcode, opcode);
  1807. int16 index = 0;
  1808. memcpy(&index, app->pBuffer, sizeof(int16));
  1809. if (index == 0xFFFF)
  1810. GetPlayer()->SetTarget(0);
  1811. else {
  1812. Spawn* spawn = GetPlayer()->GetSpawnByIndex(index);
  1813. if(spawn)
  1814. GetPlayer()->SetTarget(spawn);
  1815. else {
  1816. LogWrite(PLAYER__ERROR, 1, "Player", "Player %s tried to target %u index, but that index was not valid.", GetPlayer()->GetName(), index);
  1817. }
  1818. }
  1819. if (GetPlayer()->GetTarget())
  1820. GetCurrentZone()->CallSpawnScript(GetPlayer()->GetTarget(), SPAWN_SCRIPT_TARGETED, GetPlayer());
  1821. //player->SetTarget((int16*)app->pBuffer);
  1822. break;
  1823. }
  1824. case OP_ExamineInfoRequestMsg: {
  1825. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExamineInfoRequestMsg", opcode, opcode);
  1826. HandleExamineInfoRequest(app);
  1827. break;
  1828. }
  1829. case OP_QuickbarUpdateMsg:
  1830. //case OP_QuickbarAddMsg:
  1831. {
  1832. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuickbarUpdateMsg, OP_QuickbarAddMsg", opcode, opcode);
  1833. HandleQuickbarUpdateRequest(app);
  1834. break;
  1835. }
  1836. case OP_PredictionUpdateMsg: {
  1837. LogWrite(OPCODE__DEBUG, 7, "Opcode", "Opcode 0x%X (%i): OP_PredictionUpdateMsg from %s", opcode, opcode, GetPlayer()->GetName());
  1838. if (version <= 561) {
  1839. int8 offset = 9;
  1840. if (app->pBuffer[0] == 0xFF)
  1841. offset += 2;
  1842. if (app->size > offset) {
  1843. if (player->IsCasting()) {
  1844. float distance = 0;
  1845. float x = player->GetX();
  1846. float y = player->GetY();
  1847. float z = player->GetZ();
  1848. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1849. distance = player->GetDistance(x, y, z, false);
  1850. if (distance > .5)
  1851. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1852. }
  1853. else
  1854. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1855. player_pos_changed = true;
  1856. GetPlayer()->changed = true;
  1857. GetPlayer()->info_changed = true;
  1858. GetPlayer()->vis_changed = true;
  1859. GetPlayer()->AddChangedZoneSpawn();
  1860. //DumpPacket(app);
  1861. }
  1862. }
  1863. else {
  1864. EQ2Packet* app = new EQ2Packet(OP_PredictionUpdateMsg, 0, 0);
  1865. QueuePacket(app);
  1866. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1867. }
  1868. break;
  1869. }
  1870. case OP_RemoteCmdMsg: {
  1871. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RemoteCmdMsg", opcode, opcode);
  1872. if (app->size > 0) {
  1873. EQ2_CommandString remote(app->pBuffer, app->size);
  1874. LogWrite(PACKET__DEBUG, 1, "Packet", "RemoteCmdMsg Packet dump:");
  1875. #if EQDEBUG >= 9
  1876. DumpPacket(app);
  1877. #endif
  1878. commands.Process(remote.handler, &remote.command, this);
  1879. }
  1880. else //bad client, disconnect
  1881. Disconnect();
  1882. break;
  1883. }
  1884. case OP_CancelSpellCast: {
  1885. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CancelSpellCast", opcode, opcode);
  1886. current_zone->Interrupted(player, 0, 0, true);
  1887. SimpleMessage(CHANNEL_SPELLS_OTHER, "You stop casting.");
  1888. break;
  1889. }
  1890. case OP_UpdatePositionMsg: {
  1891. LogWrite(OPCODE__DEBUG, 7, "Opcode", "Opcode 0x%X (%i): OP_UpdatePositionMsg from %s", opcode, opcode, GetPlayer()->GetName());
  1892. int8 offset = 13;
  1893. if (app->pBuffer[0] == 0xFF)
  1894. offset += 2;
  1895. if (app->size > offset) {
  1896. if (player->IsCasting()) {
  1897. float distance = 0;
  1898. float x = player->GetX();
  1899. float y = player->GetY();
  1900. float z = player->GetZ();
  1901. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1902. distance = player->GetDistance(x, y, z, false);
  1903. if (distance > .5)
  1904. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1905. }
  1906. else
  1907. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1908. player_pos_changed = true;
  1909. GetPlayer()->changed = true;
  1910. GetPlayer()->info_changed = true;
  1911. GetPlayer()->vis_changed = true;
  1912. GetPlayer()->AddChangedZoneSpawn();
  1913. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1914. //DumpPacket(app);
  1915. }
  1916. break;
  1917. }
  1918. case OP_MailSendMessageMsg: {
  1919. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MailSendMessageMsg", opcode, opcode);
  1920. HandleSentMail(app);
  1921. break;
  1922. }
  1923. case OP_StopTrackingMsg: {
  1924. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopTrackingMsg", opcode, opcode);
  1925. player->GetZone()->RemovePlayerTracking(player, TRACKING_STOP);
  1926. break;
  1927. }
  1928. case OP_BeginTrackingMsg: {
  1929. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginTrackingMsg", opcode, opcode);
  1930. PacketStruct* packet = configReader.getStruct("WS_BeginTracking", GetVersion());
  1931. if (packet) {
  1932. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1933. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1934. Spawn* spawn = player->GetSpawnWithPlayerID(spawn_id);
  1935. if (spawn) {
  1936. AddWaypoint(spawn->GetName(), WAYPOINT_CATEGORY_TRACKING, spawn_id);
  1937. BeginWaypoint(spawn->GetName(), spawn->GetX(), spawn->GetY(), spawn->GetZ());
  1938. player->GetZone()->RemovePlayerTracking(player, TRACKING_CLOSE_WINDOW);
  1939. }
  1940. }
  1941. safe_delete(packet);
  1942. }
  1943. break;
  1944. }
  1945. case OP_BioUpdateMsg: {
  1946. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BioUpdateMsg", opcode, opcode);
  1947. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  1948. if (packet) {
  1949. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1950. player->SetBiography(packet->getType_EQ2_16BitString_ByName("biography").data);
  1951. }
  1952. safe_delete(packet);
  1953. }
  1954. break;
  1955. }
  1956. case OP_RewardPackMsg: {
  1957. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RewardPackMsg", opcode, opcode);
  1958. /* This logging is still here because I remember another system using this packet and just want to make sure we can figure out that it's being sent
  1959. when we come across it (scatman) */
  1960. const char* name = app->GetOpcodeName();
  1961. if (name)
  1962. LogWrite(WORLD__DEBUG, 0, "World", "%s Received OP_RewardPackMsg %04i", name, app->GetRawOpcode());
  1963. else
  1964. LogWrite(WORLD__DEBUG, 0, "World", "Received OP_RewardPackMsg %04i", app->GetRawOpcode());
  1965. //DumpPacket(app);
  1966. PacketStruct* packet = configReader.getStruct("WS_RewardPackMsg", GetVersion());
  1967. if (packet) {
  1968. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1969. string recruiter_name = packet->getType_EQ2_16BitString_ByName("recruiter_name").data;
  1970. /* Player has contacted a guild recruiter */
  1971. if (recruiter_name.length() > 0) {
  1972. Guild* guild = guild_list.GetGuild(packet->getType_int32_ByName("guild_id"));
  1973. Client* recruiter = zone_list.GetClientByCharName(recruiter_name);
  1974. if (recruiter && guild) {
  1975. Message(CHANNEL_GUILD_EVENT, "Contact request sent to %s of %s.", recruiter->GetPlayer()->GetName(), guild->GetName());
  1976. recruiter->Message(CHANNEL_GUILD_EVENT, "%s [%u %s], [0 Unskilled] (%s) is requesting to speak to YOU about joining the guild.", player->GetName(), player->GetLevel(), classes.GetClassNameCase(player->GetAdventureClass()).c_str(), races.GetRaceNameCase(player->GetRace()));
  1977. recruiter->PlaySound("ui_guild_page");
  1978. }
  1979. }
  1980. /* New picture taken for guild recruiting */
  1981. else {
  1982. //DumpPacket(app->pBuffer, app->size);
  1983. int32 guild_id = 0;
  1984. int16 picture_data_size = 0;
  1985. unsigned char* recruiter_picture_data = 0;
  1986. memcpy(&guild_id, app->pBuffer + 4, sizeof(int32));
  1987. memcpy(&picture_data_size, app->pBuffer + 15, sizeof(int16));
  1988. Guild* guild = guild_list.GetGuild(guild_id);
  1989. if (guild) {
  1990. GuildMember* gm = guild->GetGuildMember(player);
  1991. if (gm) {
  1992. safe_delete_array(gm->recruiter_picture_data);
  1993. recruiter_picture_data = new unsigned char[picture_data_size];
  1994. for (int16 i = 0; i < picture_data_size; i++)
  1995. memcpy(recruiter_picture_data + i, app->pBuffer + 17 + i, 2);
  1996. gm->recruiter_picture_data = recruiter_picture_data;
  1997. gm->recruiter_picture_data_size = picture_data_size;
  1998. guild->SetMemberSaveNeeded(true);
  1999. }
  2000. }
  2001. }
  2002. }
  2003. safe_delete(packet);
  2004. }
  2005. break;
  2006. }
  2007. case OP_PetOptions: {
  2008. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PetOptions", opcode, opcode);
  2009. Spawn* target = player->GetTarget();
  2010. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  2011. if (packet && target && (target == player->GetPet() || target == player->GetCharmedPet() || target == player->GetDeityPet() || target == player->GetCosmeticPet())) {
  2012. bool change = false;
  2013. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  2014. string name = packet->getType_EQ2_16BitString_ByName("pet_name").data;
  2015. if (strlen(name.c_str()) != 0 && SetPetName(name.c_str())) {
  2016. target->SetName(name.c_str());
  2017. GetCurrentZone()->SendUpdateTitles(target);
  2018. change = true;
  2019. }
  2020. int8 pet_behavior = player->GetInfoStruct()->get_pet_behavior();
  2021. // Check protect self setting and update if needed
  2022. if (packet->getType_int8_ByName("protect_self") == 1) {
  2023. if ((pet_behavior & 2) == 0) {
  2024. player->GetInfoStruct()->set_pet_behavior(pet_behavior + 2);
  2025. change = true;
  2026. }
  2027. }
  2028. else {
  2029. if ((pet_behavior & 2) != 0) {
  2030. player->GetInfoStruct()->set_pet_behavior(pet_behavior - 2);
  2031. change = true;
  2032. }
  2033. }
  2034. // Check protect master setting and update if needed
  2035. if (packet->getType_int8_ByName("protect_master") == 1) {
  2036. if ((pet_behavior & 1) == 0) {
  2037. player->GetInfoStruct()->set_pet_behavior(pet_behavior + 1);
  2038. change = true;
  2039. }
  2040. }
  2041. else {
  2042. if ((pet_behavior & 1) != 0) {
  2043. player->GetInfoStruct()->set_pet_behavior(pet_behavior - 1);
  2044. change = true;
  2045. }
  2046. }
  2047. int8 pet_movement = player->GetInfoStruct()->get_pet_movement();
  2048. // Check stay/follow setting and update if needed
  2049. if (packet->getType_int8_ByName("stay_follow_toggle") == 1) {
  2050. if (pet_movement != 2) {
  2051. player->GetInfoStruct()->set_pet_movement(2);
  2052. change = true;
  2053. }
  2054. }
  2055. else {
  2056. if (pet_movement != 1) {
  2057. player->GetInfoStruct()->set_pet_movement(1);
  2058. change = true;
  2059. }
  2060. }
  2061. // Ranged/Melee settings are not implemented yet
  2062. if (change)
  2063. player->SetCharSheetChanged(true);
  2064. }
  2065. safe_delete(packet);
  2066. }
  2067. break;
  2068. }
  2069. case OP_RecipeBook: {
  2070. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RecipeBook", opcode, opcode);
  2071. SendRecipeList();
  2072. break;
  2073. }
  2074. case OP_BuyPlayerHouseMsg: {
  2075. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BuyPlayerHouseMsg", opcode, opcode);
  2076. //DumpPacket(app);
  2077. int64 bank_money = GetPlayer()->GetBankCoinsPlat();
  2078. PacketStruct* packet = configReader.getStruct("WS_BuyHouse", GetVersion());
  2079. if (packet) {
  2080. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  2081. int64 house_id = 0;
  2082. if(GetVersion() <= 561) {
  2083. house_id = packet->getType_int32_ByName("house_id");
  2084. }
  2085. else {
  2086. house_id = packet->getType_int64_ByName("house_id");
  2087. }
  2088. HouseZone* hz = world.GetHouseZone(house_id);
  2089. if (hz) {
  2090. bool got_bank_money = BankHasCoin(hz->cost_coin);
  2091. int8 disable_alignment_req = rule_manager.GetGlobalRule(R_Player, DisableHouseAlignmentRequirement)->GetInt8();
  2092. std::vector<PlayerHouse*> houses = world.GetAllPlayerHouses(GetCharacterID());
  2093. if (houses.size() > 24)
  2094. {
  2095. SimpleMessage(CHANNEL_COLOR_YELLOW, "You already own 25 houses and may not own another.");
  2096. safe_delete(packet);
  2097. break;
  2098. }
  2099. if(disable_alignment_req && hz->alignment > 0 && hz->alignment != GetPlayer()->GetAlignment())
  2100. {
  2101. std::string req = "You must be of ";
  2102. if (hz->alignment == 1)
  2103. req.append("Good");
  2104. else
  2105. req.append("Evil");
  2106. req.append(" alignment to purchase this house");
  2107. SimpleMessage(CHANNEL_COLOR_YELLOW, req.c_str());
  2108. safe_delete(packet);
  2109. break;
  2110. }
  2111. int32 status_req = hz->cost_status;
  2112. int32 available_status = player->GetInfoStruct()->get_status_points();
  2113. if (status_req <= available_status && (!hz->cost_coin || (hz->cost_coin && player->RemoveCoins(hz->cost_coin))))
  2114. {
  2115. player->GetInfoStruct()->subtract_status_points(status_req);
  2116. ZoneServer* instance_zone = zone_list.GetByInstanceID(0, hz->zone_id, false, false);
  2117. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800; // 604800 = 7 days
  2118. int64 unique_id = database.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, instance_zone->GetInstanceID(), upkeep_due);
  2119. world.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, unique_id, instance_zone->GetInstanceID(), upkeep_due, 0, 0, GetPlayer()->GetName());
  2120. //ClientPacketFunctions::SendHousingList(this);
  2121. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(unique_id);
  2122. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 561 ? house_id : this->GetPlayer()->GetID());
  2123. PlaySound("coin_cha_ching");
  2124. }
  2125. else if (status_req <= available_status && got_bank_money == 1) {
  2126. player->GetInfoStruct()->subtract_status_points(status_req);
  2127. bool bankwithdrawl = BankWithdrawalNoBanker(hz->cost_coin);
  2128. //this should NEVER happen since we check with got_bank_money, however adding it here should something go nutty.
  2129. if (bankwithdrawl == 0) {
  2130. PlaySound("buy_failed");
  2131. SimpleMessage(CHANNEL_COLOR_RED, "There was an error in bankwithdrawl function.");
  2132. safe_delete(packet);
  2133. break;
  2134. }
  2135. ZoneServer* instance_zone = zone_list.GetByInstanceID(0, hz->zone_id, false, false);
  2136. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800; // 604800 = 7 days
  2137. int64 unique_id = database.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, instance_zone->GetInstanceID(), upkeep_due);
  2138. world.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, unique_id, instance_zone->GetInstanceID(), upkeep_due, 0, 0, GetPlayer()->GetName());
  2139. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(unique_id);
  2140. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 561 ? house_id : this->GetPlayer()->GetID());
  2141. PlaySound("coin_cha_ching");
  2142. }
  2143. else
  2144. {
  2145. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money to purchase the house.");
  2146. PlaySound("buy_failed");
  2147. }
  2148. }
  2149. }
  2150. }
  2151. safe_delete(packet);
  2152. break;
  2153. }
  2154. case OP_EnterHouseMsg: {
  2155. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EnterHouseMsg", opcode, opcode);
  2156. //DumpPacket(app);
  2157. PacketStruct* packet = configReader.getStruct("WS_EnterHouse", GetVersion());
  2158. if (packet) {
  2159. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  2160. PlayerHouse* ph = nullptr;
  2161. HouseZone* hz = nullptr;
  2162. int64 house_id = 0;
  2163. int32 spawn_index = 0;
  2164. if(GetVersion() <= 561) {
  2165. spawn_index = packet->getType_int32_ByName("house_id");
  2166. }
  2167. else {
  2168. house_id = packet->getType_int64_ByName("house_id");
  2169. }
  2170. ZoneServer* house = GetHouseZoneServer(spawn_index, house_id);
  2171. if (house) {
  2172. Zone(house, true);
  2173. }
  2174. }
  2175. }
  2176. safe_delete(packet);
  2177. break;
  2178. }
  2179. case OP_PayHouseUpkeepMsg: {
  2180. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PayHouseUpkeepMsg", opcode, opcode);
  2181. PacketStruct* packet = configReader.getStruct("WS_PayUpkeep", GetVersion());
  2182. if (packet) {
  2183. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  2184. int64 house_id = 0;
  2185. if(GetVersion() <= 561) {
  2186. house_id = packet->getType_int32_ByName("house_id");
  2187. }
  2188. else {
  2189. house_id = packet->getType_int64_ByName("house_id");
  2190. }
  2191. HouseZone* hz = nullptr;
  2192. PlayerHouse* ph = world.GetPlayerHouse(this, GetVersion() <= 561 ? house_id : 0, GetVersion() > 561 ? house_id : 0, &hz);
  2193. if (ph)
  2194. {
  2195. if (!hz)
  2196. {
  2197. Message(CHANNEL_COLOR_YELLOW, "HouseZone ID %u does NOT exist!", ph->house_id);
  2198. safe_delete(packet);
  2199. break;
  2200. }
  2201. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800;
  2202. if (((sint64)ph->upkeep_due - (sint64)Timer::GetUnixTimeStamp()) > 0)
  2203. {
  2204. upkeep_due = ph->upkeep_due + 604800; // 604800 = 7 days
  2205. if (upkeep_due > (Timer::GetUnixTimeStamp() + 7257600)) // 84 days max upkeep to pay https://eq2.zam.com/wiki/Housing_%28EQ2%29#Upkeep
  2206. {
  2207. Message(CHANNEL_COLOR_YELLOW, "You cannot pay more than 3 months of upkeep.");
  2208. PlaySound("buy_failed");
  2209. safe_delete(packet);
  2210. break;
  2211. }
  2212. }
  2213. bool escrowChange = false;
  2214. int64 statusReq = hz->upkeep_status;
  2215. int64 tmpRecoverStatus = 0;
  2216. if(ph->escrow_status && statusReq >= ph->escrow_status )
  2217. {
  2218. escrowChange = true;
  2219. tmpRecoverStatus = ph->escrow_status;
  2220. statusReq -= ph->escrow_status;
  2221. ph->escrow_status = 0;
  2222. }
  2223. else if (ph->escrow_status && statusReq && statusReq <= ph->escrow_status)
  2224. {
  2225. escrowChange = true;
  2226. ph->escrow_status -= statusReq;
  2227. tmpRecoverStatus = statusReq;
  2228. statusReq = 0;
  2229. }
  2230. int64 coinReq = hz->upkeep_coin;
  2231. int64 tmpRecoverCoins = 0;
  2232. if (ph->escrow_coins && coinReq >= ph->escrow_coins) // more required to upkeep than in escrow, subtract what we have left
  2233. {
  2234. escrowChange = true;
  2235. tmpRecoverCoins = ph->escrow_coins;
  2236. coinReq -= ph->escrow_coins;
  2237. ph->escrow_coins = 0;
  2238. }
  2239. else if (ph->escrow_coins && coinReq && coinReq <= ph->escrow_coins)
  2240. {
  2241. escrowChange = true;
  2242. // more than enough in escrow, subtract and make our cost 0!
  2243. ph->escrow_coins -= coinReq;
  2244. tmpRecoverCoins = coinReq;
  2245. coinReq = 0;
  2246. }
  2247. int32 available_status_points = player->GetInfoStruct()->get_status_points();
  2248. if(!statusReq || (statusReq && statusReq <= available_status_points))
  2249. {
  2250. if(coinReq && player->RemoveCoins(coinReq))
  2251. coinReq = 0;
  2252. if(!coinReq && statusReq && player->GetInfoStruct()->subtract_status_points(statusReq))
  2253. statusReq = 0;
  2254. }
  2255. bool got_bank_money = BankHasCoin(hz->upkeep_coin);
  2256. if (!coinReq && !statusReq) // TODO: Need option to take from bank if player does not have enough coin on them
  2257. {
  2258. database.AddHistory(ph, GetPlayer()->GetName(), "Paid Upkeep", Timer::GetUnixTimeStamp(), hz->upkeep_coin, 0, 0);
  2259. if (escrowChange)
  2260. database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins, ph->escrow_status);
  2261. ph->upkeep_due = upkeep_due;
  2262. database.SetHouseUpkeepDue(GetCharacterID(), ph->house_id, ph->instance_id, ph->upkeep_due);
  2263. //ClientPacketFunctions::SendHousingList(this);
  2264. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 561 ? house_id : this->GetPlayer()->GetID());
  2265. PlaySound("coin_cha_ching");
  2266. }
  2267. else if (!statusReq && got_bank_money == 1) {
  2268. bool bankwithdrawl = BankWithdrawalNoBanker(hz->upkeep_coin);
  2269. //this should NEVER happen since we check with got_bank_money, however adding it here should something go nutty.
  2270. if (bankwithdrawl == 0) {
  2271. PlaySound("buy_failed");
  2272. SimpleMessage(CHANNEL_COLOR_RED, "There was an error in bankwithdrawl function.");
  2273. safe_delete(packet);
  2274. break;
  2275. }
  2276. database.AddHistory(ph, GetPlayer()->GetName(), "Paid Upkeep", Timer::GetUnixTimeStamp(), hz->upkeep_coin, 0, 0);
  2277. if (escrowChange)
  2278. database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins, ph->escrow_status);
  2279. ph->upkeep_due = upkeep_due;
  2280. database.SetHouseUpkeepDue(GetCharacterID(), ph->house_id, ph->instance_id, ph->upkeep_due);
  2281. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 561 ? house_id : this->GetPlayer()->GetID());
  2282. PlaySound("coin_cha_ching");
  2283. }
  2284. else
  2285. {
  2286. // recover the escrow we were going to use but could not spend due to lack of funds
  2287. if (tmpRecoverCoins)
  2288. ph->escrow_coins += tmpRecoverCoins;
  2289. if(tmpRecoverStatus)
  2290. ph->escrow_status += tmpRecoverStatus;
  2291. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money or status to pay for upkeep.");
  2292. PlaySound("buy_failed");
  2293. }
  2294. }
  2295. else
  2296. Message(CHANNEL_COLOR_YELLOW, "PlayerHouse ID %u does NOT exist!", house_id);
  2297. }
  2298. }
  2299. safe_delete(packet);
  2300. break;
  2301. }
  2302. case OP_ExitHouseMsg: {
  2303. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExitHouseMsg", opcode, opcode);
  2304. int32 instance_id = GetCurrentZone()->GetInstanceID();
  2305. if (instance_id > 0) {
  2306. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(instance_id);
  2307. if (ph) {
  2308. HouseZone* hz = world.GetHouseZone(ph->house_id);
  2309. if (hz) {
  2310. ZoneServer* new_zone = zone_list.Get(hz->exit_zone_id);
  2311. // determine if this is an instanced zone that already exists
  2312. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(hz->exit_zone_id);
  2313. if (instance_zone || new_zone) {
  2314. GetPlayer()->SetX(hz->exit_x);
  2315. GetPlayer()->SetY(hz->exit_y);
  2316. GetPlayer()->SetZ(hz->exit_z);
  2317. GetPlayer()->SetHeading(hz->exit_heading);
  2318. if (instance_zone)
  2319. Zone(instance_zone->GetInstanceID(), false, true);
  2320. else
  2321. Zone(new_zone, false);
  2322. }
  2323. }
  2324. }
  2325. }
  2326. break;
  2327. }
  2328. case OP_QuestJournalWaypointMsg: {
  2329. //DumpPacket(app);
  2330. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalWaypointMsg", opcode, opcode);
  2331. PacketStruct* packet = configReader.getStruct("WS_QuestJournalWaypoint", GetVersion());
  2332. if (packet) {
  2333. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  2334. if(GetVersion() <= 561) {
  2335. int32 quest_id = packet->getType_int32_ByName("quest_id");
  2336. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  2337. if (player->player_quests.count(quest_id) > 0 && player->player_quests[quest_id]) {
  2338. if(player->player_quests[quest_id]->GetTracked())
  2339. player->player_quests[quest_id]->SetTracked(false);
  2340. else
  2341. player->player_quests[quest_id]->SetTracked(true);
  2342. player->player_quests[quest_id]->SetSaveNeeded(true);
  2343. }
  2344. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  2345. }
  2346. else {
  2347. int32 quests = packet->getType_int32_ByName("num_quests");
  2348. if (quests > 100) // just picking a number higher than max allowed
  2349. {
  2350. LogWrite(CCLIENT__ERROR, 0, "Client", "num_quests = %u - quantity too high, aborting load.", quests);
  2351. break;
  2352. }
  2353. LogWrite(CCLIENT__DEBUG, 0, "Client", "num_quests = %u", quests);
  2354. for (int32 i = 0; i < quests; i++) {
  2355. int32 id = packet->getType_int32_ByName("quest_id_0", i);
  2356. if (id == 0)
  2357. continue;
  2358. LogWrite(CCLIENT__DEBUG, 5, "Client", "quest_id = %u", id);
  2359. bool tracked = packet->getType_int8_ByName("quest_tracked_0", i) == 1 ? true : false;
  2360. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  2361. if (player->player_quests.count(id) > 0 && player->player_quests[id]) {
  2362. player->player_quests[id]->SetTracked(tracked);
  2363. player->player_quests[id]->SetSaveNeeded(true);
  2364. }
  2365. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  2366. }
  2367. }
  2368. }
  2369. safe_delete(packet);
  2370. }
  2371. break;
  2372. }
  2373. case OP_PaperdollImage: {
  2374. /* PacketStruct* packet = configReader.getStruct("WS_PaperdollImage", version);
  2375. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  2376. //First check if this is a new image... delete an existing partial image if one exists
  2377. int8 packet_index = packet->getType_int8_ByName("packetIndex");
  2378. if (packet_index == 0) {
  2379. safe_delete_array(incoming_paperdoll.image_bytes);
  2380. incoming_paperdoll.last_received_packet_index = 0;
  2381. incoming_paperdoll.current_size_bytes = 0;
  2382. }
  2383. //return if this packet is not the one we are expecting...
  2384. else if (packet_index != incoming_paperdoll.last_received_packet_index + 1) {
  2385. safe_delete(packet);
  2386. break;
  2387. }
  2388. //Check how many packets we're supposed to be receiving for this/these images
  2389. incoming_paperdoll.image_num_packets = packet->getType_int8_ByName("totalNumPackets");
  2390. //Check the image type, if this is a new type in the same series of packets we have a new image
  2391. int8 img_type = packet->getType_int8_ByName("image_type");
  2392. if (packet_index != 0 && img_type != incoming_paperdoll.image_type) {
  2393. //We have a new image. Save the old data and clear before continuing
  2394. SavePlayerImages();
  2395. }
  2396. incoming_paperdoll.image_type = img_type;
  2397. //Get the size of the image data in this packet
  2398. sint64 image_size = packet->getType_int32_ByName("imageSize");
  2399. if (image_size <= 0 || image_size > 1048576) {
  2400. //If this packet is saying that the array is size <= 0 or > 1 MiB return out... it shouldn't be those sizes ever
  2401. safe_delete(packet);
  2402. break;
  2403. }
  2404. //Create a new array
  2405. int32 new_image_size = image_size;
  2406. uchar* new_image = new uchar[incoming_paperdoll.current_size_bytes + new_image_size];
  2407. if (incoming_paperdoll.image_bytes) {
  2408. memcpy(new_image, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  2409. safe_delete_array(incoming_paperdoll.image_bytes);
  2410. }
  2411. //variable i should be the index in the packet of the first PNG file byte
  2412. vector<DataStruct*>* d_structs = packet->getStructs();
  2413. vector<DataStruct*>::iterator itr;
  2414. int32 i = 0;
  2415. for (itr = d_structs->begin(); itr != d_structs->end(); itr++) {
  2416. DataStruct* ds = (*itr);
  2417. if (strcmp(ds->GetName(), "pngData_0") != 0)
  2418. i += ds->GetDataSizeInBytes();
  2419. else
  2420. break;
  2421. }
  2422. //Return if this packet is bad and we would read out of bounds
  2423. if (app->size - i < new_image_size) {
  2424. safe_delete(packet);
  2425. safe_delete_array(new_image);
  2426. break;
  2427. }
  2428. uchar* tmp = new_image + incoming_paperdoll.current_size_bytes;
  2429. memcpy(tmp, app->pBuffer + i, new_image_size);
  2430. incoming_paperdoll.current_size_bytes += new_image_size;
  2431. incoming_paperdoll.image_bytes = new_image;
  2432. //Check if this is the last packet we're expecting for this image. Create a final image if so
  2433. if (incoming_paperdoll.image_num_packets == 1 ||
  2434. incoming_paperdoll.last_received_packet_index + 2 == incoming_paperdoll.image_num_packets) {
  2435. SavePlayerImages();
  2436. }
  2437. incoming_paperdoll.last_received_packet_index = packet_index;
  2438. }
  2439. safe_delete(packet);
  2440. */
  2441. break;
  2442. }
  2443. case OP_ReadyForTakeOffMsg:
  2444. {
  2445. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyForTakeOffMsg", opcode, opcode);
  2446. int32 index = GetCurrentZone()->GetFlightPathIndex(GetPendingFlightPath());
  2447. if (GetPendingFlightPath() > 0) {
  2448. if (index != -1) {
  2449. PacketStruct* packet = configReader.getStruct("WS_ClearForTakeOff", GetVersion());
  2450. if (packet) {
  2451. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  2452. packet->setDataByName("path_id", index);
  2453. packet->setDataByName("speed", GetCurrentZone()->GetFlightPathSpeed(GetPendingFlightPath()));
  2454. QueuePacket(packet->serialize());
  2455. safe_delete(packet);
  2456. on_auto_mount = true;
  2457. }
  2458. }
  2459. else {
  2460. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but unable to get an index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2461. Message(CHANNEL_ERROR, "Unable to get index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2462. EndAutoMount();
  2463. }
  2464. SetPendingFlightPath(0);
  2465. }
  2466. else
  2467. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but there is no pending flight path...");
  2468. break;
  2469. }
  2470. case OP_EarlyLandingRequestMsg:
  2471. {
  2472. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EarlyLandingRequestMsg", opcode, opcode);
  2473. EndAutoMount();
  2474. break;
  2475. }
  2476. case OP_SubmitCharCust:
  2477. {
  2478. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SubmitCharCust", opcode, opcode);
  2479. PacketStruct* packet = configReader.getStruct("WS_SubmitCharCust", version);
  2480. if (packet && packet->LoadPacketData(app->pBuffer, app->size, GetVersion() <= 561 ? false : true)) {
  2481. int8 type = packet->getType_int8_ByName("type");
  2482. if (type == 0) {
  2483. /*if (player->custNPC) {
  2484. player->custNPCTarget->CustomizeAppearance(packet);
  2485. current_zone->SendSpawnChanges(player->custNPCTarget);
  2486. }
  2487. else {*/
  2488. player->CustomizeAppearance(packet);
  2489. current_zone->SendSpawnChanges(player);
  2490. //}
  2491. }
  2492. }
  2493. safe_delete(packet);
  2494. /*
  2495. if (player->custNPC) {
  2496. memcpy(&player->appearance, &player->SavedApp, sizeof(AppearanceData));
  2497. memcpy(&player->features, &player->SavedFeatures, sizeof(CharFeatures));
  2498. if (player->custNPCTarget->IsBot())
  2499. database.SaveBotAppearance((Bot*)player->custNPCTarget);
  2500. player->custNPC = false;
  2501. player->custNPCTarget = 0;
  2502. player->changed = true;
  2503. player->info_changed = true;
  2504. current_zone->SendSpawnChanges(player, this);
  2505. }*/
  2506. break;
  2507. }
  2508. default: {
  2509. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): Unknown in %s", opcode, opcode, __FILE__);
  2510. const char* name = app->GetOpcodeName();
  2511. if (name)
  2512. LogWrite(OPCODE__DEBUG, 1, "Opcode", "%s Received %04X (%i)", name, app->GetRawOpcode(), app->GetRawOpcode());
  2513. else
  2514. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Received %04X (%i)", app->GetRawOpcode(), app->GetRawOpcode());
  2515. // keeping this around for debugging purposes
  2516. DumpPacket(app);
  2517. }
  2518. }
  2519. if (!eqs || !eqs->CheckActive()) {
  2520. return false;
  2521. }
  2522. return ret;
  2523. }
  2524. bool Client::HandleLootItem(Spawn* entity, Item* item, Spawn* target, bool overrideLootRestrictions) {
  2525. if (!item) {
  2526. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find item to loot!");
  2527. return false;
  2528. }
  2529. int32 conflictItemList = 0, conflictequipmentList = 0, conflictAppearanceEquipmentList = 0;
  2530. int16 lore_stack_count = 0;
  2531. Player* lootingPlayer = player;
  2532. Client* lootingClient = this;
  2533. if (target != nullptr && target != lootingPlayer && target->IsPlayer()) {
  2534. lootingPlayer = (Player*)target;
  2535. lootingClient = lootingPlayer->GetClient();
  2536. }
  2537. // needs to only be checked before expiration of loot restrictions
  2538. if (entity && !overrideLootRestrictions) {
  2539. if (entity->GetLootGroupID() > 0 && (!lootingPlayer->GetGroupMemberInfo() || lootingPlayer->GetGroupMemberInfo()->group_id != entity->GetLootGroupID())) {
  2540. LogWrite(LOOT__ERROR, 0, "Loot", "%s: Loot Group ID from %s did not match Item: %s (%u), expected group id %u.", entity->GetName(), lootingPlayer->GetName(), item->name.c_str(), item->details.item_id, entity->GetLootGroupID());
  2541. return false;
  2542. }
  2543. if (entity->GetLootMethod() != GroupLootMethod::METHOD_FFA) {
  2544. switch (entity->GetLootMethod()) {
  2545. case GroupLootMethod::METHOD_LEADER: {
  2546. if (entity->GetLootGroupID() > 0 && (!lootingPlayer->GetGroupMemberInfo() || (lootingPlayer->GetGroupMemberInfo() && (lootingPlayer->GetGroupMemberInfo()->group_id != entity->GetLootGroupID() || !lootingPlayer->GetGroupMemberInfo()->leader)))) {
  2547. LogWrite(LOOT__ERROR, 0, "Loot", "%s: Loot Attempt from %s was not allowed with Item: %s (%u), must be group leader.", entity->GetName(), lootingPlayer->GetName(), item->name.c_str(), item->details.item_id);
  2548. return false;
  2549. }
  2550. break;
  2551. }
  2552. case GroupLootMethod::METHOD_LOTTO:
  2553. case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
  2554. if (entity->IsLootTimerRunning()) {
  2555. LogWrite(LOOT__INFO, 0, "Loot", "%s: Loot Timer is still running, flag player %s to lotto Item: %s (%u).", entity->GetName(), lootingPlayer->GetName(), item->name.c_str(), item->details.item_id);
  2556. return false;
  2557. }
  2558. break;
  2559. }
  2560. }
  2561. }
  2562. }
  2563. if (((conflictItemList = lootingPlayer->item_list.CheckSlotConflict(item, true, true, &lore_stack_count)) == LORE ||
  2564. (conflictequipmentList = lootingPlayer->equipment_list.CheckSlotConflict(item, true, &lore_stack_count)) == LORE ||
  2565. (conflictAppearanceEquipmentList = lootingPlayer->appearance_equipment_list.CheckSlotConflict(item, true, &lore_stack_count)) == LORE) && !item->CheckFlag(STACK_LORE)) {
  2566. Message(CHANNEL_COLOR_RED, "You cannot loot %s due to lore conflict.", item->name.c_str());
  2567. return false;
  2568. }
  2569. else if (conflictItemList == STACK_LORE || conflictequipmentList == STACK_LORE || conflictAppearanceEquipmentList == STACK_LORE) {
  2570. Message(CHANNEL_COLOR_RED, "You cannot loot %s due to stack lore conflict.", item->name.c_str());
  2571. return false;
  2572. }
  2573. if (lootingPlayer->item_list.HasFreeSlot() || lootingPlayer->item_list.CanStack(item)) {
  2574. if (lootingPlayer->item_list.AssignItemToFreeSlot(item)) {
  2575. if (item->CheckFlag2(HEIRLOOM)) { // TODO: RAID Support
  2576. GroupMemberInfo* gmi = lootingClient->GetPlayer()->GetGroupMemberInfo();
  2577. if (gmi && gmi->group_id)
  2578. {
  2579. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  2580. if (group)
  2581. {
  2582. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  2583. deque<GroupMemberInfo*>* members = group->GetMembers();
  2584. if (members) {
  2585. for (int8 i = 0; i < members->size(); i++) {
  2586. Entity* member = members->at(i)->member;
  2587. if (!member)
  2588. continue;
  2589. if ((member->GetZone() != lootingClient->GetPlayer()->GetZone()))
  2590. continue;
  2591. if (member->IsPlayer()) {
  2592. item->grouped_char_ids.insert(std::make_pair(((Player*)member)->GetCharacterID(), true));
  2593. item->save_needed = true;
  2594. }
  2595. }
  2596. }
  2597. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  2598. }
  2599. }
  2600. }
  2601. int8 type = CHANNEL_LOOT;
  2602. if (entity) {
  2603. lootingClient->Message(type, "You loot %s from the corpse of %s", item->CreateItemLink(GetVersion()).c_str(), entity->GetName());
  2604. }
  2605. else {
  2606. lootingClient->Message(type, "You found a %s.", item->CreateItemLink(GetVersion()).c_str());
  2607. }
  2608. Guild* guild = lootingPlayer->GetGuild();
  2609. if (guild && item->details.tier >= ITEM_TAG_LEGENDARY) {
  2610. char adjective[32];
  2611. int8 type;
  2612. memset(adjective, 0, sizeof(adjective));
  2613. if (item->details.tier >= ITEM_TAG_MYTHICAL) {
  2614. strncpy(adjective, "Mythical", sizeof(adjective) - 1);
  2615. type = GUILD_EVENT_LOOTS_MYTHICAL_ITEM;
  2616. }
  2617. else if (item->details.tier >= ITEM_TAG_FABLED) {
  2618. strncpy(adjective, "Fabled", sizeof(adjective) - 1);
  2619. type = GUILD_EVENT_LOOTS_FABELED_ITEM;
  2620. }
  2621. else {
  2622. strncpy(adjective, "Legendary", sizeof(adjective) - 1);
  2623. type = GUILD_EVENT_LOOTS_LEGENDARY_ITEM;
  2624. }
  2625. guild->AddNewGuildEvent(type, "%s has looted the %s %s", Timer::GetUnixTimeStamp(), true, lootingPlayer->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2626. guild->SendMessageToGuild(type, "%s has looted the %s %s", lootingPlayer->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2627. }
  2628. if (item->GetItemScript() && lua_interface)
  2629. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, lootingPlayer);
  2630. lootingClient->CheckPlayerQuestsItemUpdate(item);
  2631. if (GetVersion() <= 561) {
  2632. EQ2Packet* outapp = lootingPlayer->SendInventoryUpdate(GetVersion());
  2633. if (outapp)
  2634. lootingClient->QueuePacket(outapp);
  2635. }
  2636. return true;
  2637. }
  2638. else
  2639. lootingClient->SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  2640. }
  2641. else
  2642. lootingClient->SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to loot item: Inventory is FULL.");
  2643. return false;
  2644. }
  2645. bool Client::HandleLootItemByID(Spawn* entity, int32 item_id, Spawn* target) {
  2646. if (!entity) {
  2647. return false;
  2648. }
  2649. Item* item = entity->LootItem(item_id);
  2650. bool success = false;
  2651. success = HandleLootItem(entity, item, target);
  2652. if (!success)
  2653. entity->AddLootItem(item);
  2654. return success;
  2655. }
  2656. void Client::HandleLootItemRequestPacket(EQApplicationPacket* app) {
  2657. PacketStruct* packet = configReader.getStruct("WS_LootItem", GetVersion());
  2658. if (packet) {
  2659. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  2660. int32 loot_id = packet->getType_int32_ByName("loot_id");
  2661. bool loot_all = (packet->getType_int8_ByName("loot_all") == 1);
  2662. int32 target_id = packet->getType_int32_ByName("target_id");
  2663. int8 button_clicked = packet->getType_int8_ByName("button_clicked");
  2664. Spawn* spawn = GetCurrentZone()->GetSpawnByID(loot_id);
  2665. if(!spawn) {
  2666. safe_delete(packet);
  2667. return;
  2668. }
  2669. Item* item = nullptr;
  2670. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  2671. if (items) {
  2672. int32 items_looted = 0;
  2673. int32 item_id = packet->getType_int32_ByName("item_id_0");
  2674. for (int32 i = 0; i < items->size(); i++) {
  2675. Item* master_item = items->at(i);
  2676. if (master_item && (loot_all || master_item->details.item_id == item_id)) {
  2677. item = new Item(master_item);
  2678. if (item) {
  2679. loot_all = HandleLootItem(0, item);
  2680. if (loot_all) {
  2681. player->RemovePendingLootItem(loot_id, item->details.item_id);
  2682. if (GetVersion() <= 561) {
  2683. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2684. if (outapp)
  2685. QueuePacket(outapp);
  2686. }
  2687. if(master_item->details.item_id == item_id) {
  2688. break;
  2689. }
  2690. }
  2691. }
  2692. if (!loot_all)
  2693. break;
  2694. }
  2695. }
  2696. if(((loot_all && !item_id) || (loot_all && item_id && items->size() == 1)) || items->size() < 1) {
  2697. CloseLoot(loot_id);
  2698. }
  2699. else {
  2700. vector<Item*>* items2 = player->GetPendingLootItems(loot_id);
  2701. SendLootResponsePacket(spawn->GetLootCoins(), items2, spawn, true);
  2702. safe_delete(items2);
  2703. }
  2704. safe_delete(items);
  2705. safe_delete(packet);
  2706. return;
  2707. }
  2708. spawn->LockLoot();
  2709. bool unlockedLoot = false;
  2710. if (spawn && !spawn->Alive() && spawn->IsNPC() && ((NPC*)spawn)->Brain()->CheckLootAllowed(player)) {
  2711. if (loot_all) {
  2712. switch (spawn->GetLootMethod()) {
  2713. case GroupLootMethod::METHOD_LOTTO: {
  2714. spawn->AddLottoItemRequest(0xFFFFFFFF, GetPlayer()->GetID());
  2715. break;
  2716. }
  2717. case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
  2718. spawn->AddNeedGreedItemRequest(0xFFFFFFFF, GetPlayer()->GetID(), true);
  2719. }
  2720. default: {
  2721. if (!unlockedLoot) {
  2722. spawn->UnlockLoot();
  2723. unlockedLoot = true;
  2724. }
  2725. int32 item_id = 0;
  2726. while (loot_all && ((item_id = spawn->GetLootItemID()) > 0)) {
  2727. loot_all = HandleLootItemByID(spawn, item_id, GetPlayer());
  2728. }
  2729. break;
  2730. }
  2731. }
  2732. spawn->UnlockLoot();
  2733. if (spawn->GetLootMethod() == GroupLootMethod::METHOD_LOTTO) {
  2734. CloseLoot(loot_id);
  2735. }
  2736. }
  2737. else {
  2738. int8 item_count = packet->getType_int8_ByName("item_count");
  2739. for (int8 cur = 0; cur < item_count; cur++) {
  2740. char item_field_name[64];
  2741. snprintf(item_field_name, 64, "item_id_%u", cur);
  2742. int32 item_id = packet->getType_int32_ByName(item_field_name);
  2743. Spawn* target = this->GetPlayer();
  2744. if (target_id != 0xFFFFFFFF && GetPlayer()->GetGroupMemberInfo()) {
  2745. Spawn* destTarget = GetPlayer()->GetSpawnWithPlayerID(target_id);
  2746. if (destTarget && (!destTarget->IsPlayer() || !world.GetGroupManager()->IsInGroup(GetPlayer()->GetGroupMemberInfo()->group_id, ((Player*)destTarget)))) {
  2747. SimpleMessage(CHANNEL_COMMAND_TEXT, "HACKS!!");
  2748. safe_delete(packet);
  2749. spawn->UnlockLoot();
  2750. return;
  2751. }
  2752. target = destTarget;
  2753. }
  2754. bool breakLoopAllLooted = false;
  2755. switch (spawn->GetLootMethod()) {
  2756. case GroupLootMethod::METHOD_LOTTO: {
  2757. spawn->AddLottoItemRequest(item_id, GetPlayer()->GetID());
  2758. break;
  2759. }
  2760. case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
  2761. if (button_clicked == 3) { // decline
  2762. break;
  2763. }
  2764. if (GetVersion() <= 561) {
  2765. button_clicked = 1; // selecting is need
  2766. }
  2767. spawn->AddNeedGreedItemRequest(item_id, GetPlayer()->GetID(), (button_clicked == 1));
  2768. break;
  2769. }
  2770. default: {
  2771. if (!unlockedLoot) {
  2772. spawn->UnlockLoot();
  2773. unlockedLoot = true;
  2774. }
  2775. if (!loot_all) {
  2776. HandleLootItemByID(spawn, item_id, target);
  2777. }
  2778. else {
  2779. while (loot_all && ((item_id = spawn->GetLootItemID()) > 0)) {
  2780. loot_all = HandleLootItemByID(spawn, item_id, target);
  2781. }
  2782. breakLoopAllLooted = true;
  2783. }
  2784. break;
  2785. }
  2786. }
  2787. if (breakLoopAllLooted) {
  2788. break;
  2789. }
  2790. }
  2791. if (!unlockedLoot) {
  2792. spawn->UnlockLoot();
  2793. }
  2794. if (spawn->GetLootMethod() == GroupLootMethod::METHOD_LOTTO ||
  2795. (spawn->GetLootMethod() == GroupLootMethod::METHOD_NEED_BEFORE_GREED && item_count >= spawn->GetLootCount())) {
  2796. CloseLoot(loot_id);
  2797. }
  2798. }
  2799. if (GetVersion() > 561) {
  2800. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2801. if (outapp)
  2802. QueuePacket(outapp);
  2803. }
  2804. if (spawn->GetLootMethod() != GroupLootMethod::METHOD_LOTTO && spawn->GetLootMethod() != GroupLootMethod::METHOD_NEED_BEFORE_GREED) {
  2805. LootSpawnRequest(spawn);
  2806. }
  2807. else {
  2808. spawn->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
  2809. }
  2810. if (!spawn->HasLoot()) {
  2811. CloseLoot(loot_id);
  2812. if (spawn->IsNPC())
  2813. GetCurrentZone()->RemoveDeadSpawn(spawn);
  2814. }
  2815. }
  2816. else {
  2817. spawn->UnlockLoot();
  2818. if (!spawn) {
  2819. LogWrite(WORLD__ERROR, 0, "World", "Unknown id of %u when looting!", loot_id);
  2820. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn to loot!");
  2821. }
  2822. else
  2823. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not unable to loot that at this time.");
  2824. }
  2825. }
  2826. safe_delete(packet);
  2827. }
  2828. }
  2829. void Client::HandleSkillInfoRequest(EQApplicationPacket* app) {
  2830. PacketStruct* request = 0;
  2831. // cout << "Request: \n";
  2832. // DumpPacket(app);
  2833. switch (app->pBuffer[0]) {
  2834. case 0: { //items
  2835. request = configReader.getStruct("WS_SkillInfoItemRequest", GetVersion());
  2836. if (request) {
  2837. if(request->LoadPacketData(app->pBuffer, app->size)) {
  2838. Item* item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(request->getType_int32_ByName("unique_id"));
  2839. if (!item)
  2840. item = GetPlayer()->item_list.GetItemFromUniqueID(request->getType_int32_ByName("unique_id"), true);
  2841. if (item) {
  2842. PacketStruct* response = configReader.getStruct("WS_SkillInfoItemResponse", GetVersion());
  2843. if (response) {
  2844. response->setDataByName("request_type", request->getType_int32_ByName("request_type"));
  2845. response->setDataByName("unique_id", request->getType_int32_ByName("unique_id"));
  2846. response->setSmallStringByName("name", item->name.c_str());
  2847. EQ2Packet* app2 = response->serialize();
  2848. //DumpPacket(app2);
  2849. QueuePacket(app2);
  2850. safe_delete(response);
  2851. }
  2852. }
  2853. }
  2854. safe_delete(request);
  2855. }
  2856. break;
  2857. }
  2858. case 2: {//spells
  2859. request = configReader.getStruct("WS_SkillInfoSpellRequest", GetVersion());
  2860. if (request) {
  2861. if(request->LoadPacketData(app->pBuffer, app->size)) {
  2862. int32 id = request->getType_int32_ByName("id");
  2863. int8 tier = request->getType_int32_ByName("unique_id"); //on live this is really unique_id, but I'm going to make it tier instead :)
  2864. Spell* spell = master_spell_list.GetSpell(id, tier);
  2865. PacketStruct* response = configReader.getStruct("WS_SkillInfoResponse", GetVersion());
  2866. if (response) {
  2867. response->setDataByName("request_type", 2);
  2868. response->setDataByName("unique_id", tier);
  2869. response->setDataByName("id", id);
  2870. if (spell)
  2871. response->setSmallStringByName("name", spell->GetName());
  2872. else
  2873. response->setSmallStringByName("name", "Unknown Spell");
  2874. EQ2Packet* app2 = response->serialize();
  2875. // DumpPacket(app2);
  2876. QueuePacket(app2);
  2877. safe_delete(response);
  2878. }
  2879. }
  2880. safe_delete(request);
  2881. }
  2882. break;
  2883. }
  2884. default: {
  2885. LogWrite(WORLD__ERROR, 0, "World", "Unknown SkillInfoRequest type of %i", (int)app->pBuffer[0]);
  2886. }
  2887. }
  2888. safe_delete(request);
  2889. }
  2890. void Client::HandleExamineInfoRequest(EQApplicationPacket* app) {
  2891. PacketStruct* request = 0;
  2892. if (!app || app->size == 0)
  2893. return;
  2894. //LogWrite(CCLIENT__DEBUG, 0, "Client", "Request2:");
  2895. int8 type = app->pBuffer[0];
  2896. DumpPacket(app->pBuffer,app->size);
  2897. //283: item: 0, effect: 1, recipe: 2, spell: 3
  2898. if (version <= 373) {
  2899. if (type == 1)
  2900. type = 4;
  2901. else if (type == 2)
  2902. type = 5;
  2903. }
  2904. if (type == 3) {
  2905. Spell* spell = 0;
  2906. bool trait_display;
  2907. request = configReader.getStruct((GetVersion() <= 373) ? "WS_ExamineInfoRequest" : "WS_ExamineInfoRequestMsg", GetVersion());
  2908. if (!request) {
  2909. return;
  2910. }
  2911. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  2912. safe_delete(request);
  2913. return;
  2914. }
  2915. int32 id = request->getType_int32_ByName("id");
  2916. int32 tier = request->getType_int32_ByName("tier");
  2917. int32 trait_tier = request->getType_int32_ByName("unknown_id");
  2918. bool display = true;
  2919. if (version <= 373 && request->getType_int8_ByName("display") == 1) // this is really requesting a partial packet
  2920. display = false;
  2921. else if (version <= 561)
  2922. display = request->getType_int8_ByName("display");
  2923. else if (version > 561)
  2924. display = false; // clients default is false otherwise it pops up a window when hovering over the knowledge book abilities
  2925. LogWrite(CCLIENT__DEBUG, 5, "Client", "Client::HandleExamineInfoRequest from %s: Type: (%i) Tier: (%u) Unknown ID: (%u) Item ID: (%u)",GetPlayer()->GetName(),type,tier,trait_tier,id);
  2926. if (trait_tier != 0xFFFFFFFF) {
  2927. spell = master_spell_list.GetSpell(id, trait_tier);
  2928. if (!spell) {
  2929. spell = master_spell_list.GetSpell(id, trait_tier + 1);
  2930. }
  2931. trait_display = true;
  2932. }
  2933. else {
  2934. spell = master_spell_list.GetSpell(id, tier);
  2935. trait_display = false;
  2936. }
  2937. // if we can't find it on the master spell list, see if it is a custom spell
  2938. if (!spell)
  2939. {
  2940. lua_interface->FindCustomSpellLock();
  2941. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2942. if (tmpSpell)
  2943. spell = tmpSpell->spell;
  2944. lua_interface->FindCustomSpellUnlock();
  2945. }
  2946. if(!spell) { // fix ui timeout for classic, isle of refuge, dof, kos clients
  2947. int8 playerTier = GetPlayer()->GetSpellTier(id);
  2948. spell = master_spell_list.GetSpell(id, playerTier);
  2949. LogWrite(CCLIENT__WARNING, 0, "Client", "Client::HandleExamineInfoRequest from %s: Failed to find tier 1 spell. Last resort try to get the spell from the player book, spell %u, tier %u", GetPlayer()->GetName(),id,playerTier);
  2950. }
  2951. if (spell && !CountSentSpell(spell->GetSpellID(), spell->GetSpellTier())) {
  2952. if (!spell->IsCopiedSpell())
  2953. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  2954. EQ2Packet* app = spell->SerializeSpell(this, display, trait_display);
  2955. //DumpPacket(app);
  2956. QueuePacket(app);
  2957. }
  2958. else if(spell && GetVersion() <=561 && CountSentSpell(spell->GetSpellID(), spell->GetSpellTier())) {
  2959. EQ2Packet* app = spell->SerializeSpell(this, display, trait_display, GetVersion() <= 561 ? true : false);
  2960. //DumpPacket(app);
  2961. QueuePacket(app);
  2962. }
  2963. else {
  2964. LogWrite(CCLIENT__ERROR, 0, "Client", "Client::HandleExamineInfoRequest from %s: Failed to successfully send Type: (%i) Tier: (%u) Unknown ID: (%u) Item ID: (%u)",GetPlayer()->GetName(),type,tier,trait_tier,id);
  2965. }
  2966. }
  2967. else if (type == 0) {
  2968. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2969. if (!request) {
  2970. return;
  2971. }
  2972. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  2973. safe_delete(request);
  2974. return;
  2975. }
  2976. int32 id = request->getType_int32_ByName("id");
  2977. Item* item = 0;
  2978. // translate from unique id to spawn id for houses
  2979. Spawn* spawn = this->GetCurrentZone()->GetSpawnFromUniqueItemID(id);
  2980. bool wasSpawn = false;
  2981. if (spawn)
  2982. {
  2983. item = master_item_list.GetItem(spawn->GetPickupItemID());
  2984. if (item)
  2985. {
  2986. wasSpawn = true;
  2987. item = new Item(item);
  2988. item->details.unique_id = spawn->GetPickupUniqueItemID();
  2989. }
  2990. }
  2991. if (!item)
  2992. item = GetPlayer()->item_list.GetItemFromUniqueID(id, true);
  2993. if (!item)
  2994. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(id);
  2995. if (!item)
  2996. item = GetPlayer()->GetAppearanceEquipmentList()->GetItemFromUniqueID(id);
  2997. if (!item)
  2998. item = master_item_list.GetItem(id);
  2999. if (item) {// && sent_item_details.count(id) == 0){
  3000. MItemDetails.writelock(__FUNCTION__, __LINE__);
  3001. sent_item_details[id] = true;
  3002. MItemDetails.releasewritelock(__FUNCTION__, __LINE__);
  3003. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  3004. QueuePacket(app);
  3005. if (wasSpawn)
  3006. delete item;
  3007. }
  3008. else {
  3009. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  3010. DumpPacket(app);
  3011. }
  3012. }
  3013. else if (type == 1) {
  3014. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  3015. if (!request) {
  3016. return;
  3017. }
  3018. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  3019. safe_delete(request);
  3020. return;
  3021. }
  3022. int32 id = request->getType_int32_ByName("id");
  3023. int32 unique_id = request->getType_int32_ByName("unique_id");
  3024. Item* item = GetPlayer()->item_list.GetItemFromUniqueID(unique_id, true);
  3025. if (!item)
  3026. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(unique_id);
  3027. if (!item)
  3028. item = GetPlayer()->GetAppearanceEquipmentList()->GetItemFromUniqueID(unique_id);
  3029. if (!item)
  3030. item = master_item_list.GetItem(id);
  3031. if (item) {
  3032. MItemDetails.writelock(__FUNCTION__, __LINE__);
  3033. sent_item_details[id] = true;
  3034. MItemDetails.releasewritelock(__FUNCTION__, __LINE__);
  3035. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  3036. QueuePacket(app);
  3037. }
  3038. else {
  3039. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  3040. DumpPacket(app);
  3041. }
  3042. }
  3043. else if (type == 2) {
  3044. request = configReader.getStruct("WS_ExamineInfoItemLinkRequest", GetVersion());
  3045. if (!request) {
  3046. return;
  3047. }
  3048. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  3049. safe_delete(request);
  3050. return;
  3051. }
  3052. int32 id = request->getType_int32_ByName("item_id");
  3053. LogWrite(CCLIENT__DEBUG, 5, "Client", "Client::HandleExamineInfoRequest from %s: Found Type: (%i) Item ID: (%u)",GetPlayer()->GetName(),type,id);
  3054. //int32 unknown_0 = request->getType_int32_ByName("unknown",0);
  3055. //int32 unknown_1 = request->getType_int32_ByName("unknown",1);
  3056. //int8 unknown2 = request->getType_int8_ByName("unknown2");
  3057. //int32 unique_id = request->getType_int32_ByName("unique_id");
  3058. //int16 unknown5 = request->getType_sint16_ByName("unknown5");
  3059. //printf("Type: (%i) Unknown_0: (%u) Unknown_1: (%u) Unknown2: (%i) Unique ID: (%u) Unknown5: (%i) Item ID: (%u)\n",type,unknown_0,unknown_1,unknown2,unique_id,unknown5,id);
  3060. Item* item = master_item_list.GetItem(id);
  3061. if (item) {
  3062. //only display popup for non merchant links
  3063. EQ2Packet* app = item->serialize(GetVersion(), (request->getType_int8_ByName("show_popup") != 0), GetPlayer(), true, 0, 0, GetVersion() > 561 ? true : false);
  3064. QueuePacket(app);
  3065. }
  3066. else {
  3067. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  3068. DumpPacket(app);
  3069. }
  3070. }
  3071. else if (type == 4) { //spell effect
  3072. request = configReader.getStruct("WS_ExamineSpellEffectRequest", GetVersion());
  3073. if (!request) {
  3074. return;
  3075. }
  3076. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  3077. safe_delete(request);
  3078. return;
  3079. }
  3080. int32 id = request->getType_int32_ByName("id");
  3081. int16 display = request->getType_int8_ByName("partial_info");
  3082. SpellEffects* effect = player->GetSpellEffect(id);
  3083. //printf("Type: (%i) Unknown5: (%i) Item ID: (%u)\n",type,unknown5,id);
  3084. if (effect) {
  3085. LogWrite(CCLIENT__DEBUG, 5, "Client", "Client::HandleExamineInfoRequest from %s: Found Type: (%i) Item ID: (%u)",GetPlayer()->GetName(),type,id);
  3086. int8 tier = effect->tier;
  3087. Spell* spell = master_spell_list.GetSpell(id, tier);
  3088. // if we can't find it on the master spell list, see if it is a custom spell
  3089. if (!spell)
  3090. {
  3091. lua_interface->FindCustomSpellLock();
  3092. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  3093. EQ2Packet* pack = 0;
  3094. if (tmpSpell)
  3095. spell = tmpSpell->spell;
  3096. lua_interface->FindCustomSpellUnlock();
  3097. }
  3098. if (spell && (version <= 561 || !CountSentSpell(id, tier))) { // fix DoF and KoS clients UI Timeout
  3099. if (!spell->IsCopiedSpell())
  3100. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  3101. int8 type = 0;
  3102. if (version <= 373)
  3103. type = 1;
  3104. EQ2Packet* app = spell->SerializeSpecialSpell(this, false, type, 0x81);
  3105. //DumpPacket(app);
  3106. QueuePacket(app);
  3107. }
  3108. }
  3109. else {
  3110. LogWrite(CCLIENT__ERROR, 0, "Client", "Client::HandleExamineInfoRequest from %s: Cannot Find Type: (%i) Item ID: (%u)",GetPlayer()->GetName(),type,id);
  3111. }
  3112. }
  3113. else if (type == 5) { // recipe info
  3114. request = configReader.getStruct((GetVersion() <= 373) ? "WS_ExamineInfoRequest" : "WS_ExamineInfoRequestMsg", GetVersion());
  3115. if (!request)
  3116. return;
  3117. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  3118. safe_delete(request);
  3119. return;
  3120. }
  3121. int32 id = 0;
  3122. if(GetVersion() < 546) {
  3123. id = request->getType_int32_ByName("id");
  3124. }
  3125. else if(GetVersion() <= 561) {
  3126. id = request->getType_int32_ByName("unique_id");
  3127. }
  3128. else {
  3129. id = request->getType_int32_ByName("unknown_id");
  3130. }
  3131. Recipe* recipe = master_recipe_list.GetRecipe(id);
  3132. if (recipe) {
  3133. EQ2Packet* app = recipe->SerializeRecipe(this, recipe, false, GetItemPacketType(GetVersion()), 0x02);
  3134. //DumpPacket(app);
  3135. QueuePacket(app);
  3136. }
  3137. }
  3138. else if (type == 6) { // AA spell info
  3139. Spell* spell = 0;
  3140. //Spell* spell2 = 0;
  3141. //AltAdvanceData* data = 0;
  3142. request = configReader.getStruct((GetVersion() <= 373) ? "WS_ExamineInfoRequest" : "WS_ExamineInfoRequestMsg", GetVersion());
  3143. if (!request)
  3144. return;
  3145. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  3146. safe_delete(request);
  3147. return;
  3148. }
  3149. int32 id = request->getType_int32_ByName("id");
  3150. int32 tier = GetPlayer()->GetSpellTier(id);
  3151. LogWrite(WORLD__INFO, 0, "World", "Examine Info Request->Unique ID: %u Tier: %u ", id, tier);
  3152. //data = master_aa_list.GetAltAdvancement(id);
  3153. //LogWrite(WORLD__INFO, 0, "World", "SOE Spell CRC: %u", data->spell_crc);
  3154. //spell = master_spell_list.GetSpellByCRC(data->spell_crc);
  3155. spell = master_spell_list.GetSpell(id, tier);
  3156. if (!spell)
  3157. spell = master_spell_list.GetSpell(id, 1);
  3158. if (!spell)
  3159. {
  3160. lua_interface->FindCustomSpellLock();
  3161. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  3162. if (tmpSpell)
  3163. spell = tmpSpell->spell;
  3164. lua_interface->FindCustomSpellUnlock();
  3165. }
  3166. if (!spell)
  3167. {
  3168. LogWrite(CCLIENT__ERROR, 0, "Client", "WORLD", "Client::HandleExamineInfoRequest from %s: FAILED Examine Info Request-> Spell ID: %u, tier: %i", GetPlayer()->GetName(), id, tier);
  3169. return;
  3170. }
  3171. //if (spell && sent_spell_details.count(spell->GetSpellID()) == 0) {
  3172. if (!spell->IsCopiedSpell())
  3173. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  3174. // EQ2Packet* app = spell->SerializeAASpell(this,tier, data, false, GetItemPacketType(GetVersion()), 0x04);
  3175. LogWrite(WORLD__INFO, 0, "WORLD", "Examine Info Request-> Spell ID: %u", spell->GetSpellID());
  3176. if(GetVersion() > 561) {
  3177. EQ2Packet* app = master_spell_list.GetAASpellPacket(id, tier, this, false, 0x4F);//0x45 change version to match client
  3178. /////////////////////////////////////////GetAASpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type) {
  3179. //DumpPacket(app);
  3180. QueuePacket(app);
  3181. }
  3182. //}
  3183. }
  3184. else {
  3185. LogWrite(CCLIENT__ERROR, 0, "World", "Client::HandleExamineInfoRequest from %s: Unknown examine request: %i", GetPlayer()->GetName(), (int)type);
  3186. DumpPacket(app);
  3187. }
  3188. safe_delete(request);
  3189. }
  3190. void Client::HandleQuickbarUpdateRequest(EQApplicationPacket* app) {
  3191. PacketStruct* request = configReader.getStruct("WS_QuickBarUpdateRequest", GetVersion());
  3192. if (request) {
  3193. if(request->LoadPacketData(app->pBuffer, app->size)) {
  3194. int32 id = request->getType_int32_ByName("id");
  3195. int32 bar = request->getType_int32_ByName("hotbar_number");
  3196. int32 slot = request->getType_int32_ByName("hotkey_slot");
  3197. int32 type = request->getType_int32_ByName("type");
  3198. int8 tier = request->getType_int32_ByName("unique_id");
  3199. EQ2_16BitString text = request->getType_EQ2_16BitString_ByName("text");
  3200. Spell* spell = 0;
  3201. if (type == 0xFFFFFFFF)
  3202. GetPlayer()->RemoveQuickbarItem(bar, slot);
  3203. else {
  3204. if (type == QUICKBAR_NORMAL)
  3205. spell = master_spell_list.GetSpell(id, tier);
  3206. if (spell)
  3207. GetPlayer()->AddQuickbarItem(bar, slot, type, spell->GetSpellIcon(), spell->GetSpellIconBackdrop(), id, tier, 0, text.data.c_str());
  3208. else
  3209. GetPlayer()->AddQuickbarItem(bar, slot, type, 0, 0, id, 0, 0, text.data.c_str());
  3210. }
  3211. }
  3212. safe_delete(request);
  3213. }
  3214. }
  3215. bool Client::Process(bool zone_process) {
  3216. bool ret = true;
  3217. // EQS can become null if player is linkdead, we want to always be able to process the camp/linkdead timers when active
  3218. if ((camp_timer && camp_timer->Check()) || (linkdead_timer && linkdead_timer->Check())) {
  3219. ResetSendMail();
  3220. if(getConnection())
  3221. getConnection()->SendDisconnect(false);
  3222. safe_delete(camp_timer);
  3223. if(linkdead_timer) {
  3224. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player %s triggered linkdead timer, disconnecting", GetPlayer()->GetName());
  3225. // we remove the linkdead status and force a camp out immediately
  3226. if((GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_LINKDEAD) > 0) {
  3227. GetPlayer()->SetActivityStatus(GetPlayer()->GetActivityStatus() - ACTIVITY_STATUS_LINKDEAD);
  3228. }
  3229. if ((GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0) {
  3230. GetPlayer()->SetActivityStatus(GetPlayer()->GetActivityStatus() + ACTIVITY_STATUS_CAMPING);
  3231. }
  3232. }
  3233. safe_delete(linkdead_timer);
  3234. ret = false;
  3235. }
  3236. if (!eqs) {
  3237. return false;
  3238. }
  3239. if ((connected_to_zone && !zone_process) || (!connected_to_zone && zone_process)) {
  3240. return true;
  3241. }
  3242. switch(new_client_login) {
  3243. case NewLoginState::LOGIN_SEND: {
  3244. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendLoginInfo to new client...");
  3245. SendLoginInfo();
  3246. new_client_login = NewLoginState::LOGIN_NONE;
  3247. break;
  3248. }
  3249. case NewLoginState::LOGIN_INITIAL_LOAD: {
  3250. bool isDBActive = database.IsActiveQuery(GetCharacterID());
  3251. // wait for starting skills/spells to load and reload from DB.
  3252. if(!isDBActive) {
  3253. if (GetPlayer()->GetInfoStruct()->get_reload_player_spells()) {
  3254. database.LoadCharacterSpells(GetCharacterID(), GetPlayer());
  3255. GetPlayer()->GetInfoStruct()->set_reload_player_spells(0);
  3256. }
  3257. new_client_login = NewLoginState::LOGIN_SEND;
  3258. }
  3259. break;
  3260. }
  3261. case NewLoginState::LOGIN_ALLOWED: {
  3262. int32 count = 0;
  3263. if(!GetPlayer()->IsReturningFromLD())
  3264. {
  3265. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Skills for player '%s'...", player->GetName());
  3266. count = database.LoadCharacterSkills(GetCharacterID(), player);
  3267. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Spells for player '%s'...", player->GetName());
  3268. count = database.LoadCharacterSpells(GetCharacterID(), player);
  3269. }
  3270. else
  3271. {
  3272. LogWrite(CCLIENT__INFO, 0, "Client", "Player is returning from linkdead status (Player does not need reload) thus skipping database loading for '%s'...", player->GetName());
  3273. }
  3274. // get the latest character starting skills / spells, may have been updated after character creation
  3275. if(GetPlayer()->GetInfoStruct()->get_first_world_login()) {
  3276. world.SyncCharacterAbilities(this);
  3277. Query query;
  3278. query.AddQueryAsync(GetCharacterID(), &database, Q_UPDATE, "UPDATE characters set first_world_login = 0 where id=%u", GetCharacterID());
  3279. GetPlayer()->GetInfoStruct()->set_first_world_login(0);
  3280. }
  3281. new_client_login = NewLoginState::LOGIN_INITIAL_LOAD;
  3282. break;
  3283. }
  3284. case NewLoginState::LOGIN_DELAYED: {
  3285. if(!delay_msg_timer.Enabled() || delay_msg_timer.Check()) {
  3286. LogWrite(CCLIENT__INFO, 0, "Client", "Wait for zone %s to load for new client %s...", GetCurrentZone()->GetZoneName(), GetPlayer()->GetName());
  3287. delay_msg_timer.Start(1000, true);
  3288. }
  3289. if(!GetCurrentZone()->IsLoading()) {
  3290. new_client_login = NewLoginState::LOGIN_ALLOWED;
  3291. }
  3292. return true;
  3293. break;
  3294. }
  3295. }
  3296. delay_msg_timer.Disable();
  3297. sockaddr_in to;
  3298. memset((char*)&to, 0, sizeof(to));
  3299. to.sin_family = AF_INET;
  3300. to.sin_port = port;
  3301. to.sin_addr.s_addr = ip;
  3302. /************ Get all packets from packet manager out queue and process them ************/
  3303. EQApplicationPacket* app = 0;
  3304. if (eqs && !eqs->CheckActive()) {
  3305. num_active_failures++;
  3306. LogWrite(CCLIENT__DEBUG, 7, "Client", "%s, num_active_failures = %i", __FUNCTION__, num_active_failures);
  3307. if (num_active_failures > 100) {
  3308. return false;
  3309. }
  3310. return true;
  3311. }
  3312. while (ret && eqs && (app = eqs->PopPacket())) {
  3313. ret = HandlePacket(app);
  3314. LogWrite(CCLIENT__DEBUG, 5, "Client", "Func: %s, Line: %i, Opcode: '%s'", __FUNCTION__, __LINE__, app->GetOpcodeName());
  3315. delete app;
  3316. }
  3317. if (GetCurrentZone() && !GetCurrentZone()->IsLoading() && GetCurrentZone()->GetSpawnByID(GetPlayer()->GetID()) && should_load_spells) {
  3318. //database.LoadCharacterActiveSpells(player);
  3319. player->UnlockAllSpells(true);
  3320. should_load_spells = false;
  3321. }
  3322. if(spawn_removal_timer.Check() && GetPlayer()) {
  3323. GetPlayer()->ProcessSpawnRangeUpdates();
  3324. GetPlayer()->CheckSpawnStateQueue();
  3325. }
  3326. if (delayedLogin && delayTimer.Enabled() && delayTimer.Check())
  3327. {
  3328. if (!HandleNewLogin(delayedAccountID, delayedAccessKey))
  3329. return false;
  3330. }
  3331. if (quest_updates) {
  3332. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, ProcessQuestUpdates", __FUNCTION__, __LINE__);
  3333. ProcessQuestUpdates();
  3334. }
  3335. int32 queue_timer_delay = rule_manager.GetGlobalRule(R_Client, QuestQueueTimer)->GetInt32();
  3336. if(queue_timer_delay < 10) {
  3337. queue_timer_delay = 10;
  3338. }
  3339. if (last_update_time > 0 && last_update_time < (Timer::GetCurrentTime2() - queue_timer_delay)) {
  3340. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, CheckQuestQueue", __FUNCTION__, __LINE__);
  3341. CheckQuestQueue();
  3342. }
  3343. MSaveSpellStateMutex.lock();
  3344. if(save_spell_state_timer.Check())
  3345. {
  3346. save_spell_state_timer.Disable();
  3347. GetPlayer()->SaveSpellEffects();
  3348. }
  3349. MSaveSpellStateMutex.unlock();
  3350. if (temp_placement_timer.Check()) {
  3351. if(GetTempPlacementSpawn() && GetPlayer()->WasSentSpawn(GetTempPlacementSpawn()->GetID()) && !hasSentTempPlacementSpawn) {
  3352. SendMoveObjectMode(GetTempPlacementSpawn(), 0);
  3353. hasSentTempPlacementSpawn = true;
  3354. temp_placement_timer.Disable();
  3355. }
  3356. }
  3357. if (pos_update.Check())
  3358. {
  3359. ProcessStateCommands();
  3360. GetPlayer()->ResetMentorship(); // check if we need to asynchronously reset mentorship
  3361. if(GetPlayer()->GetRegionMap())
  3362. GetPlayer()->GetRegionMap()->TicRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  3363. if(!player_pos_changed && IsReadyForUpdates() && player_pos_timer < Timer::GetCurrentTime2() && enabled_player_pos_timer) {
  3364. if(version > 373) {
  3365. GetPlayer()->info_changed = true;
  3366. GetPlayer()->vis_changed = true;
  3367. GetPlayer()->position_changed = true;
  3368. GetPlayer()->changed = true;
  3369. GetPlayer()->AddChangedZoneSpawn();
  3370. }
  3371. player_pos_timer = Timer::GetCurrentTime2()+5000;
  3372. enabled_player_pos_timer = false;
  3373. }
  3374. if(player_pos_changed && IsReadyForUpdates()) {
  3375. player_pos_timer = Timer::GetCurrentTime2()+500;
  3376. enabled_player_pos_timer = true;
  3377. if(!underworld_cooldown_timer.Enabled() || (underworld_cooldown_timer.Enabled() && underworld_cooldown_timer.Check())) {
  3378. bool underworld = false;
  3379. if(rule_manager.GetGlobalRule(R_Zone, UseMapUnderworldCoords)->GetBool()) {
  3380. if(GetCurrentZone()->GetUnderWorld() != -1000000.0f) {
  3381. if(GetPlayer()->GetY() < GetCurrentZone()->GetUnderWorld())
  3382. underworld = true;
  3383. }
  3384. else if(GetPlayer()->GetMap() && GetPlayer()->GetMap()->GetMinY() != 9999999.0f && GetPlayer()->GetY() < (GetPlayer()->GetMap()->GetMinY() + rule_manager.GetGlobalRule(R_Zone, MapUnderworldCoordOffset)->GetFloat())) {
  3385. underworld = true;
  3386. }
  3387. }
  3388. else if(GetPlayer()->GetMap() && GetPlayer()->GetY() < GetCurrentZone()->GetUnderWorld()) {
  3389. underworld = true;
  3390. }
  3391. if(underworld) {
  3392. player->SetX(GetCurrentZone()->GetSafeX());
  3393. player->SetY(GetCurrentZone()->GetSafeY());
  3394. player->SetZ(GetCurrentZone()->GetSafeZ());
  3395. player->SetHeading(GetCurrentZone()->GetSafeHeading());
  3396. EQ2Packet* app = GetPlayer()->Move(player->GetX(), player->GetY(), player->GetZ(), GetVersion(), player->GetHeading());
  3397. if(app){
  3398. QueuePacket(app);
  3399. }
  3400. SimpleMessage(CHANNEL_COLOR_RED, "You have been teleported to a safe location in the zone, because you appeared to have fallen through the world.");
  3401. }
  3402. underworld_cooldown_timer.Start();
  3403. }
  3404. //GetPlayer()->CalculateLocation();
  3405. client_list.CheckPlayersInvisStatus(this);
  3406. player_pos_changed = false;
  3407. GetCurrentZone()->CheckTransporters(this);
  3408. if(GetPlayer()->GetRegionMap())
  3409. {
  3410. GetPlayer()->GetRegionMap()->MapRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  3411. }
  3412. }
  3413. else if (IsReadyForUpdates() && GetPlayer()->GetRegionMap()) {
  3414. GetPlayer()->GetRegionMap()->UpdateRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  3415. }
  3416. }
  3417. if (lua_interface && lua_debug && lua_debug_timer.Check())
  3418. lua_interface->UpdateDebugClients(this);
  3419. if (quest_pos_timer.Check())
  3420. CheckPlayerQuestsLocationUpdate();
  3421. if (player->GetSkills()->HasSkillUpdates()) {
  3422. vector<Skill*>* skills = player->GetSkills()->GetSkillUpdates();
  3423. if (skills) {
  3424. Skill* skill = 0;
  3425. vector<Skill*>::iterator itr;
  3426. for (itr = skills->begin(); itr != skills->end(); itr++) {
  3427. skill = *itr;
  3428. SkillChanged(skill, skill->previous_val, skill->current_val);
  3429. }
  3430. EQ2Packet* app = GetPlayer()->skill_list.GetSkillPacket(GetVersion());
  3431. if (app) QueuePacket(app);
  3432. safe_delete(skills);
  3433. }
  3434. }
  3435. m_resurrect.writelock(__FUNCTION__, __LINE__);
  3436. if (current_rez.should_delete || (current_rez.expire_timer && current_rez.expire_timer->Check(false))) {
  3437. safe_delete(current_rez.expire_timer);
  3438. current_rez.expire_timer = 0;
  3439. current_rez.active = false;
  3440. current_rez.caster = 0;
  3441. current_rez.crit = false;
  3442. current_rez.crit_mod = 0;
  3443. current_rez.expire_timer = 0;
  3444. current_rez.heal_name = "";
  3445. current_rez.hp_perc = 0;
  3446. current_rez.mp_perc = 0;
  3447. current_rez.no_calcs = false;
  3448. current_rez.range = 0;
  3449. current_rez.should_delete = false;
  3450. current_rez.spell_name = "";
  3451. current_rez.spell_visual = 0;
  3452. current_rez.subspell = 0;
  3453. }
  3454. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  3455. // Quest timers
  3456. Quest* failed_step = 0;
  3457. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  3458. if (quest_timers.size() > 0) {
  3459. vector<int32>::iterator itr;
  3460. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  3461. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  3462. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  3463. if (player_quests->count(*itr) > 0 && player_quests->at(*itr)->GetStepTimer() != 0) {
  3464. Quest* quest = player_quests->at(*itr);
  3465. if (Timer::GetUnixTimeStamp() >= quest->GetStepTimer()) {
  3466. failed_step = quest;
  3467. break;
  3468. }
  3469. }
  3470. else {
  3471. itr = quest_timers.erase(itr);
  3472. break;
  3473. }
  3474. }
  3475. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  3476. }
  3477. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  3478. if (failed_step)
  3479. failed_step->StepFailed(failed_step->GetTimerStep());
  3480. if (player->ControlFlagsChanged())
  3481. player->SendControlFlagUpdates(this);
  3482. if (!eqs || (eqs && !eqs->CheckActive()))
  3483. ret = false;
  3484. // redundant to client disconnect
  3485. // if(!ret)
  3486. // Save();
  3487. return ret;
  3488. }
  3489. ClientList::ClientList() {
  3490. MClients.SetName("ClientList::MClients");
  3491. }
  3492. ClientList::~ClientList() {
  3493. }
  3494. void ClientList::ReloadQuests() {
  3495. list<Client*>::iterator client_iter;
  3496. Client* client = 0;
  3497. MClients.readlock(__FUNCTION__, __LINE__);
  3498. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3499. client = *client_iter;
  3500. if (client)
  3501. client->ReloadQuests();
  3502. }
  3503. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3504. }
  3505. void ClientList::CheckPlayersInvisStatus(Client* owner) {
  3506. if (!owner->GetPlayer() || (!owner->GetPlayer()->IsInvis() && !owner->GetPlayer()->IsStealthed()))
  3507. return;
  3508. list<Client*>::iterator client_iter;
  3509. Client* client = 0;
  3510. MClients.readlock(__FUNCTION__, __LINE__);
  3511. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3512. client = *client_iter;
  3513. if (client == owner || client->GetPlayer() == NULL)
  3514. continue;
  3515. if (client->GetPlayer()->CheckChangeInvisHistory((Entity*)owner->GetPlayer()))
  3516. client->GetPlayer()->GetZone()->SendSpawnChanges(owner->GetPlayer(), client, true, true);
  3517. }
  3518. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3519. }
  3520. void ClientList::RemovePlayerFromInvisHistory(int32 spawnID) {
  3521. list<Client*>::iterator client_iter;
  3522. Client* client = 0;
  3523. MClients.readlock(__FUNCTION__, __LINE__);
  3524. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3525. client = *client_iter;
  3526. if (!client->GetPlayer())
  3527. continue;
  3528. client->GetPlayer()->RemoveTargetInvisHistory(spawnID);
  3529. }
  3530. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3531. }
  3532. int32 ClientList::Count() {
  3533. return client_list.size();
  3534. }
  3535. void ClientList::Add(Client* client) {
  3536. MClients.writelock(__FUNCTION__, __LINE__);
  3537. client_list.push_back(client);
  3538. MClients.releasewritelock(__FUNCTION__, __LINE__);
  3539. }
  3540. Client* ClientList::FindByAccountID(int32 account_id) {
  3541. list<Client*>::iterator client_iter;
  3542. Client* client = 0;
  3543. Client* ret = 0;
  3544. MClients.readlock(__FUNCTION__, __LINE__);
  3545. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3546. client = *client_iter;
  3547. if (client->GetAccountID() == account_id) {
  3548. ret = client;
  3549. break;
  3550. }
  3551. }
  3552. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3553. return ret;
  3554. }
  3555. Client* ClientList::FindByName(char* charName) {
  3556. list<Client*>::iterator client_iter;
  3557. Client* client = 0;
  3558. Client* ret = 0;
  3559. MClients.readlock(__FUNCTION__, __LINE__);
  3560. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3561. client = *client_iter;
  3562. if (!client || !client->GetPlayer())
  3563. continue;
  3564. if (!strncmp(client->GetPlayer()->GetName(), charName, strlen(charName))) {
  3565. ret = client;
  3566. break;
  3567. }
  3568. }
  3569. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3570. return ret;
  3571. }
  3572. Client* ClientList::Get(int32 ip, int16 port) {
  3573. list<Client*>::iterator client_iter;
  3574. Client* client = 0;
  3575. Client* ret = 0;
  3576. MClients.readlock(__FUNCTION__, __LINE__);
  3577. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3578. client = *client_iter;
  3579. if (client->GetIP() == ip && client->GetPort() == port) {
  3580. ret = client;
  3581. break;
  3582. }
  3583. }
  3584. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3585. return ret;
  3586. }
  3587. void ClientList::Process() {
  3588. list<Client*>::iterator client_iter;
  3589. list<Client*>::iterator erase_iter;
  3590. Client* client = 0;
  3591. MClients.readlock(__FUNCTION__, __LINE__);
  3592. erase_iter = client_list.end();
  3593. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3594. client = *client_iter;
  3595. // have a sanity check because the client list can sometimes obtain null client pointers
  3596. if (!client || client->remove_from_list || (!client->Process())) { // if we should be removing from list, don't process any further
  3597. erase_iter = client_iter;
  3598. break;
  3599. }
  3600. }
  3601. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3602. if (erase_iter != client_list.end()) {
  3603. client = *erase_iter;
  3604. MClients.writelock(__FUNCTION__, __LINE__);
  3605. client_list.erase(erase_iter);
  3606. MClients.releasewritelock(__FUNCTION__, __LINE__);
  3607. if (client && !client->remove_from_list) {
  3608. struct in_addr in;
  3609. in.s_addr = client->GetIP();
  3610. LogWrite(WORLD__INFO, 0, "World", "Removing client from ip: %s port: %i", inet_ntoa(in), client->GetPort());
  3611. safe_delete(client);
  3612. }
  3613. }
  3614. }
  3615. void ClientList::RemoveConnection(EQStream* eqs) {
  3616. Client* client;
  3617. if (eqs) {
  3618. list<Client*>::iterator client_iter;
  3619. MClients.readlock(__FUNCTION__, __LINE__);
  3620. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3621. client = *client_iter;
  3622. if (client->getConnection() == eqs)
  3623. client->Disconnect(true);
  3624. }
  3625. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3626. }
  3627. }
  3628. bool ClientList::ContainsStream(EQStream* eqs) {
  3629. if (!eqs) {
  3630. return false;
  3631. }
  3632. list<Client*>::iterator client_iter;
  3633. bool ret = false;
  3634. MClients.readlock(__FUNCTION__, __LINE__);
  3635. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3636. if ((*client_iter)->getConnection() && (*client_iter)->getConnection()->GetRemotePort() == eqs->GetRemotePort() && (*client_iter)->getConnection()->GetRemoteIP() == eqs->GetRemoteIP()) {
  3637. ret = true;
  3638. break;
  3639. }
  3640. }
  3641. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3642. return ret;
  3643. }
  3644. void ClientList::Remove(Client* client, bool remove_data) {
  3645. client->remove_from_list = true;
  3646. if (remove_data) {
  3647. safe_delete(client);
  3648. }
  3649. }
  3650. void Client::SetCurrentZone(ZoneServer* zone) {
  3651. current_zone = zone;
  3652. if(player) {
  3653. player->SetZone(zone, GetVersion());
  3654. }
  3655. }
  3656. void Client::SetCurrentZone(int32 id) {
  3657. if (current_zone) {
  3658. //current_zone->GetCombat()->RemoveHate(player);
  3659. current_zone->RemoveSpawn(player, false, true, true, true, true);
  3660. }
  3661. SetCurrentZone(zone_list.Get(id));
  3662. }
  3663. void Client::SetCurrentZoneByInstanceID(int32 id, int32 zoneid) {
  3664. if (current_zone) {
  3665. //current_zone->GetCombat()->RemoveHate(player);
  3666. current_zone->RemoveSpawn(player, false, true, true, true, true);
  3667. }
  3668. SetCurrentZone(zone_list.GetByInstanceID(id, zoneid));
  3669. }
  3670. ZoneServer* Client::GetCurrentZone() {
  3671. return current_zone;
  3672. }
  3673. int8 Client::GetMessageChannelColor(int8 channel_type) {
  3674. if (GetVersion() >= 973 && GetVersion() <= 1000) {
  3675. if (channel_type == CHANNEL_LOOT)
  3676. return CHANNEL_COLOR_NEW_LOOT;
  3677. }
  3678. else if (GetVersion() >= 973) {
  3679. if (channel_type == CHANNEL_LOOT)
  3680. return CHANNEL_COLOR_NEWEST_LOOT;
  3681. }
  3682. if (GetVersion() <= 283) {
  3683. if (channel_type <=12)
  3684. return channel_type;
  3685. switch (channel_type) {
  3686. case CHANNEL_GROUP_CHAT:
  3687. case CHANNEL_GROUP_SAY:
  3688. case CHANNEL_RAID_SAY:
  3689. case CHANNEL_GUILD_CHAT:
  3690. case CHANNEL_GUILD_SAY:
  3691. case CHANNEL_OFFICER_SAY:
  3692. case CHANNEL_GUILD_MOTD:
  3693. return channel_type - 1;
  3694. case CHANNEL_PRIVATE_CHAT:
  3695. case CHANNEL_NONPLAYER_TELL:
  3696. return channel_type - 5;
  3697. case CHANNEL_PRIVATE_TELL:
  3698. case CHANNEL_TELL_FROM_CS:
  3699. return channel_type - 6;
  3700. case CHANNEL_CHAT_CHANNEL_TEXT:
  3701. case CHANNEL_OUT_OF_CHARACTER:
  3702. case CHANNEL_AUCTION:
  3703. case CHANNEL_CUSTOM_CHANNEL:
  3704. case CHANNEL_CHARACTER_TEXT:
  3705. case CHANNEL_REWARD:
  3706. case CHANNEL_DEATH:
  3707. case CHANNEL_PET_CHAT:
  3708. case CHANNEL_SKILL:
  3709. return channel_type - 7;
  3710. case CHANNEL_SPELLS:
  3711. case CHANNEL_YOU_CAST:
  3712. case CHANNEL_YOU_FAIL:
  3713. return channel_type - 8;
  3714. case CHANNEL_FRIENDLY_CAST:
  3715. case CHANNEL_FRIENDLY_FAIL:
  3716. case CHANNEL_OTHER_CAST:
  3717. case CHANNEL_OTHER_FAIL:
  3718. case CHANNEL_HOSTILE_CAST:
  3719. case CHANNEL_HOSTILE_FAIL:
  3720. case CHANNEL_WORN_OFF:
  3721. case CHANNEL_SPELLS_OTHER:
  3722. return channel_type - 9;
  3723. case CHANNEL_COMBAT:
  3724. return channel_type - 15;
  3725. case CHANNEL_HEROIC_OPPORTUNITY:
  3726. case CHANNEL_NON_MELEE_DAMAGE:
  3727. case CHANNEL_DAMAGE_SHIELD:
  3728. return channel_type - 16;
  3729. case CHANNEL_MELEE_COMBAT:
  3730. case CHANNEL_WARNINGS:
  3731. case CHANNEL_YOU_HIT:
  3732. case CHANNEL_YOU_MISS:
  3733. case CHANNEL_ATTACKER_HITS:
  3734. case CHANNEL_ATTACKER_MISSES:
  3735. return channel_type - 18;
  3736. case CHANNEL_OTHER_HIT:
  3737. case CHANNEL_OTHER_MISSES:
  3738. case CHANNEL_CRITICAL_HIT:
  3739. return channel_type - 22;
  3740. case CHANNEL_OTHER:
  3741. case CHANNEL_MONEY_SPLIT:
  3742. case CHANNEL_LOOT:
  3743. return channel_type - 30;
  3744. case CHANNEL_COMMAND_TEXT:
  3745. case CHANNEL_BROADCAST:
  3746. case CHANNEL_WHO:
  3747. case CHANNEL_COMMANDS:
  3748. case CHANNEL_MERCHANT:
  3749. case CHANNEL_MERCHANT_BUY_SELL:
  3750. case CHANNEL_CONSIDER_MESSAGE:
  3751. case CHANNEL_CON_MINUS_2:
  3752. case CHANNEL_CON_MINUS_1:
  3753. case CHANNEL_CON_0:
  3754. case CHANNEL_CON_1:
  3755. case CHANNEL_CON_2:
  3756. return channel_type - 31;
  3757. default: {
  3758. return CHANNEL_DEFAULT;
  3759. }
  3760. }
  3761. }
  3762. else if (GetVersion() <= 373) {
  3763. if (channel_type <=18)
  3764. return channel_type;
  3765. switch (channel_type) {
  3766. case CHANNEL_PRIVATE_CHAT:
  3767. case CHANNEL_NONPLAYER_TELL:
  3768. return 22;
  3769. case CHANNEL_PRIVATE_TELL:
  3770. case CHANNEL_TELL_FROM_CS:
  3771. return 23;
  3772. case CHANNEL_CHAT_CHANNEL_TEXT:
  3773. case CHANNEL_OUT_OF_CHARACTER:
  3774. case CHANNEL_CUSTOM_CHANNEL:
  3775. case CHANNEL_CHARACTER_TEXT:
  3776. case CHANNEL_REWARD:
  3777. case CHANNEL_DEATH:
  3778. case CHANNEL_PET_CHAT:
  3779. case CHANNEL_SKILL:
  3780. return 26;
  3781. case CHANNEL_AUCTION:
  3782. return 27;
  3783. case CHANNEL_SPELLS:
  3784. case CHANNEL_YOU_CAST:
  3785. case CHANNEL_YOU_FAIL:
  3786. return channel_type - 8;
  3787. case CHANNEL_FRIENDLY_CAST:
  3788. case CHANNEL_FRIENDLY_FAIL:
  3789. case CHANNEL_OTHER_CAST:
  3790. case CHANNEL_OTHER_FAIL:
  3791. case CHANNEL_HOSTILE_CAST:
  3792. case CHANNEL_HOSTILE_FAIL:
  3793. case CHANNEL_WORN_OFF:
  3794. case CHANNEL_SPELLS_OTHER:
  3795. return channel_type - 9;
  3796. case CHANNEL_COMBAT:
  3797. return channel_type - 15;
  3798. case CHANNEL_HEROIC_OPPORTUNITY:
  3799. case CHANNEL_NON_MELEE_DAMAGE:
  3800. case CHANNEL_DAMAGE_SHIELD:
  3801. return channel_type - 16;
  3802. case CHANNEL_MELEE_COMBAT:
  3803. case CHANNEL_WARNINGS:
  3804. case CHANNEL_YOU_HIT:
  3805. case CHANNEL_YOU_MISS:
  3806. case CHANNEL_ATTACKER_HITS:
  3807. case CHANNEL_ATTACKER_MISSES:
  3808. return channel_type - 18;
  3809. case CHANNEL_OTHER_HIT:
  3810. case CHANNEL_OTHER_MISSES:
  3811. case CHANNEL_CRITICAL_HIT:
  3812. return channel_type - 22;
  3813. case CHANNEL_OTHER:
  3814. case CHANNEL_MONEY_SPLIT:
  3815. case CHANNEL_LOOT:
  3816. return channel_type - 30;
  3817. case CHANNEL_COMMAND_TEXT:
  3818. case CHANNEL_BROADCAST:
  3819. case CHANNEL_WHO:
  3820. case CHANNEL_COMMANDS:
  3821. case CHANNEL_MERCHANT:
  3822. case CHANNEL_MERCHANT_BUY_SELL:
  3823. case CHANNEL_CONSIDER_MESSAGE:
  3824. case CHANNEL_CON_MINUS_2:
  3825. case CHANNEL_CON_MINUS_1:
  3826. case CHANNEL_CON_0:
  3827. case CHANNEL_CON_1:
  3828. case CHANNEL_CON_2:
  3829. return 68;
  3830. default: {
  3831. return CHANNEL_DEFAULT;
  3832. }
  3833. }
  3834. }
  3835. else if (GetVersion() <= 561) {
  3836. if (channel_type < 20)
  3837. return channel_type;
  3838. switch (channel_type) {
  3839. case CHANNEL_GUILD_MOTD:
  3840. case CHANNEL_GUILD_MEMBER_ONLINE:
  3841. case CHANNEL_GUILD_EVENT:
  3842. return channel_type + 1;
  3843. case CHANNEL_PRIVATE_CHAT:
  3844. case CHANNEL_NONPLAYER_TELL:
  3845. return channel_type - 1;
  3846. case CHANNEL_PRIVATE_TELL:
  3847. case CHANNEL_TELL_FROM_CS:
  3848. case CHANNEL_ARENA:
  3849. case CHANNEL_CHAT_CHANNEL_TEXT:
  3850. case CHANNEL_OUT_OF_CHARACTER:
  3851. case CHANNEL_AUCTION:
  3852. case CHANNEL_CUSTOM_CHANNEL:
  3853. case CHANNEL_CHARACTER_TEXT:
  3854. case CHANNEL_REWARD:
  3855. case CHANNEL_DEATH:
  3856. case CHANNEL_PET_CHAT:
  3857. case CHANNEL_SKILL:
  3858. case CHANNEL_FACTION:
  3859. case CHANNEL_SPELLS:
  3860. case CHANNEL_YOU_CAST:
  3861. case CHANNEL_YOU_FAIL:
  3862. return channel_type - 2;
  3863. case CHANNEL_FRIENDLY_CAST:
  3864. case CHANNEL_FRIENDLY_FAIL:
  3865. case CHANNEL_OTHER_CAST:
  3866. case CHANNEL_OTHER_FAIL:
  3867. case CHANNEL_HOSTILE_CAST:
  3868. case CHANNEL_HOSTILE_FAIL:
  3869. case CHANNEL_WORN_OFF:
  3870. case CHANNEL_SPELLS_OTHER:
  3871. case CHANNEL_HEAL_SPELLS:
  3872. case CHANNEL_HEALS:
  3873. case CHANNEL_FRIENDLY_HEALS:
  3874. case CHANNEL_OTHER_HEALS:
  3875. case CHANNEL_HOSTILE_HEALS:
  3876. return channel_type - 3;
  3877. case CHANNEL_COMBAT:
  3878. case CHANNEL_GENERAL_COMBAT:
  3879. case CHANNEL_HEROIC_OPPORTUNITY:
  3880. case CHANNEL_NON_MELEE_DAMAGE:
  3881. case CHANNEL_DAMAGE_SHIELD:
  3882. case CHANNEL_WARD:
  3883. return channel_type - 4;
  3884. case CHANNEL_MELEE_COMBAT:
  3885. case CHANNEL_WARNINGS:
  3886. case CHANNEL_YOU_HIT:
  3887. case CHANNEL_YOU_MISS:
  3888. case CHANNEL_ATTACKER_HITS:
  3889. case CHANNEL_ATTACKER_MISSES:
  3890. case CHANNEL_YOUR_PET_HITS:
  3891. case CHANNEL_YOUR_PET_MISSES:
  3892. case CHANNEL_ATTACKER_HITS_PET:
  3893. case CHANNEL_ATTACKER_MISSES_PET:
  3894. case CHANNEL_OTHER_HIT:
  3895. case CHANNEL_OTHER_MISSES:
  3896. return channel_type - 5;
  3897. case CHANNEL_OTHER:
  3898. case CHANNEL_MONEY_SPLIT:
  3899. case CHANNEL_LOOT:
  3900. return channel_type - 14;
  3901. case CHANNEL_COMMAND_TEXT:
  3902. case CHANNEL_BROADCAST:
  3903. case CHANNEL_WHO:
  3904. case CHANNEL_COMMANDS:
  3905. case CHANNEL_MERCHANT:
  3906. case CHANNEL_MERCHANT_BUY_SELL:
  3907. case CHANNEL_CONSIDER_MESSAGE:
  3908. case CHANNEL_CON_MINUS_2:
  3909. case CHANNEL_CON_MINUS_1:
  3910. case CHANNEL_CON_0:
  3911. case CHANNEL_CON_1:
  3912. case CHANNEL_CON_2:
  3913. case CHANNEL_TRADESKILLS:
  3914. case CHANNEL_HARVESTING:
  3915. case CHANNEL_HARVESTING_WARNINGS:
  3916. return channel_type - 15;
  3917. default: {
  3918. return CHANNEL_DEFAULT;
  3919. }
  3920. }
  3921. }
  3922. else {
  3923. switch (channel_type) {
  3924. default: {
  3925. return channel_type;
  3926. }
  3927. }
  3928. }
  3929. return channel_type;
  3930. }
  3931. void Client::HandleTellMessage(Client* from, const char* message, const char* to, int32 current_language_id) {
  3932. if (!from || GetPlayer()->IsIgnored(from->GetPlayer()->GetName()))
  3933. return;
  3934. PacketStruct* packet = configReader.getStruct("WS_HearChat", GetVersion());
  3935. if (packet) {
  3936. packet->setDataByName("from", from->GetPlayer()->GetName());
  3937. packet->setDataByName("to", to);
  3938. packet->setDataByName("channel", GetMessageChannelColor(CHANNEL_PRIVATE_TELL));
  3939. packet->setDataByName("from_spawn_id", 0xFFFFFFFF);
  3940. packet->setDataByName("to_spawn_id", 0xFFFFFFFF);
  3941. packet->setDataByName("unknown2", 1, 1);
  3942. packet->setDataByName("show_bubble", 1);
  3943. if (current_language_id == 0 || GetPlayer()->HasLanguage(current_language_id)) {
  3944. packet->setDataByName("understood", 1);
  3945. }
  3946. packet->setDataByName("time", 2);
  3947. packet->setDataByName("language", current_language_id);
  3948. packet->setMediumStringByName("message", message);
  3949. EQ2Packet* outpacket = packet->serialize();
  3950. QueuePacket(outpacket);
  3951. safe_delete(packet);
  3952. }
  3953. }
  3954. void Client::SimpleMessage(int8 color, const char* message) {
  3955. PacketStruct* command_packet = configReader.getStruct("WS_DisplayText", GetVersion());
  3956. if (command_packet) {
  3957. command_packet->setDataByName("color", GetMessageChannelColor(color));//convert this to the correct client type (different clients have different chat numbers)
  3958. command_packet->setMediumStringByName("text", message);
  3959. command_packet->setDataByName("unknown02", 0x00ff);
  3960. EQ2Packet* outapp = command_packet->serialize();
  3961. QueuePacket(outapp);
  3962. safe_delete(command_packet);
  3963. }
  3964. }
  3965. void Client::SendSpellUpdate(Spell* spell, bool add_silently, bool add_to_hotbar) {
  3966. PacketStruct* packet = configReader.getStruct("WS_SpellGainedMsg", GetVersion());
  3967. if (packet) {
  3968. int8 xxx = spell->GetSpellData()->is_aa;
  3969. packet->setDataByName("spell_type", spell->GetSpellData()->type);
  3970. packet->setDataByName("spell_id", spell->GetSpellID());
  3971. packet->setDataByName("unique_id", spell->GetSpellData()->spell_name_crc);
  3972. packet->setDataByName("spell_name", spell->GetName());
  3973. if(add_silently)
  3974. packet->setDataByName("add_silently", 1);
  3975. if(add_to_hotbar)
  3976. packet->setDataByName("add_to_hotbar", 1);
  3977. packet->setDataByName("unknown", xxx);
  3978. packet->setDataByName("display_spell_tier", 1);
  3979. packet->setDataByName("unknown3", 1);
  3980. packet->setDataByName("tier", spell->GetSpellTier());
  3981. packet->setDataByName("icon", spell->GetSpellIcon());
  3982. packet->setDataByName("icon_type", spell->GetSpellIconBackdrop());
  3983. packet->setDataByName("unknown5", 0xFFFFFFFF);
  3984. //packet->PrintPacket();
  3985. EQ2Packet* outapp = packet->serialize();
  3986. //DumpPacket(outapp);
  3987. QueuePacket(outapp);
  3988. safe_delete(packet);
  3989. }
  3990. }
  3991. void Client::Message(int8 type, const char* message, ...) {
  3992. va_list argptr;
  3993. char buffer[4096];
  3994. va_start(argptr, message);
  3995. vsnprintf(buffer, sizeof(buffer), message, argptr);
  3996. va_end(argptr);
  3997. SimpleMessage(type, buffer);
  3998. }
  3999. void Client::Disconnect(bool send_disconnect)
  4000. {
  4001. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client Disconnect...");
  4002. this->Save();
  4003. this->GetPlayer()->WritePlayerStatistics();
  4004. SetConnected(false);
  4005. if (send_disconnect && getConnection())
  4006. getConnection()->SendDisconnect(true);
  4007. eqs = 0;
  4008. }
  4009. bool Client::Summon(const char* search_name) {
  4010. Spawn* target = 0;
  4011. if (search_name || GetPlayer()->GetTarget()) {
  4012. Client* search_client = 0;
  4013. if (search_name) {
  4014. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  4015. if (target && target->IsPlayer())
  4016. search_client = target->GetClient();
  4017. if (!target) {
  4018. search_client = zone_list.GetClientByCharName(string(search_name));
  4019. if (search_client)
  4020. target = search_client->GetPlayer();
  4021. }
  4022. }
  4023. else
  4024. target = GetPlayer()->GetTarget();
  4025. if (target && target != GetPlayer()) {
  4026. target->SetX(GetPlayer()->GetX());
  4027. target->SetY(GetPlayer()->GetY());
  4028. target->SetZ(GetPlayer()->GetZ());
  4029. target->SetHeading(GetPlayer()->GetHeading());
  4030. if (!target->IsPlayer()) {
  4031. target->SetSpawnOrigX(target->GetX());
  4032. target->SetSpawnOrigY(target->GetY());
  4033. target->SetSpawnOrigZ(target->GetZ());
  4034. target->SetSpawnOrigHeading(target->GetHeading());
  4035. }
  4036. target->SetLocation(GetPlayer()->GetLocation());
  4037. if(target->IsNPC()) {
  4038. ((NPC*)target)->HaltMovement();
  4039. }
  4040. }
  4041. else if (target)
  4042. Message(CHANNEL_COLOR_RED, "Error: You cannot summon yourself!");
  4043. if (search_client && search_client != this) {
  4044. search_client->Message(CHANNEL_COLOR_YELLOW, "You have been summoned by '%s'!", GetPlayer()->GetName());
  4045. Message(CHANNEL_COLOR_YELLOW, "Summoning '%s'...", search_client->GetPlayer()->GetName());
  4046. if (search_client->GetCurrentZone() != GetCurrentZone())
  4047. search_client->Zone(GetCurrentZone()->GetZoneName(), false);
  4048. else {
  4049. EQ2Packet* app = search_client->GetPlayer()->Move(GetPlayer()->GetX(), GetPlayer()->GetY(), GetPlayer()->GetZ(), search_client->GetVersion());
  4050. if (app)
  4051. search_client->QueuePacket(app);
  4052. }
  4053. }
  4054. }
  4055. if (!target)
  4056. return false;
  4057. else
  4058. return true;
  4059. }
  4060. std::string Client::IdentifyInstanceLockout(int32 zoneID, bool displayClient) {
  4061. int8 instanceType = database.GetInstanceTypeByZoneID(zoneID);
  4062. if(instanceType < 1)
  4063. return std::string("");
  4064. ZoneServer* instance_zone = nullptr;
  4065. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  4066. if (data) {
  4067. // If lockout instances check to see if we are locked out
  4068. if (instanceType == SOLO_LOCKOUT_INSTANCE || instanceType == GROUP_LOCKOUT_INSTANCE || instanceType == RAID_LOCKOUT_INSTANCE) {
  4069. int32 time = 0;
  4070. // Check success timer
  4071. if (data->last_success_timestamp > 0) {
  4072. if (Timer::GetUnixTimeStamp() < data->last_success_timestamp + data->success_lockout_time) {
  4073. // Timer has not expired yet can't re enter
  4074. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Success lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  4075. time = (data->last_success_timestamp + data->success_lockout_time) - Timer::GetUnixTimeStamp();
  4076. }
  4077. }
  4078. // Check failure timer
  4079. if (data->last_failure_timestamp > 0) {
  4080. if (Timer::GetUnixTimeStamp() < data->last_failure_timestamp + data->failure_lockout_time) {
  4081. // Timer has not expired yet
  4082. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Failure lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  4083. time = (data->last_failure_timestamp + data->failure_lockout_time) - Timer::GetUnixTimeStamp();
  4084. }
  4085. }
  4086. // Time > 0 then we are locked out, make the message and send it and return true
  4087. if (time > 0) {
  4088. string time_msg = "";
  4089. int16 hour;
  4090. int8 min;
  4091. int8 sec;
  4092. hour = time / 3600;
  4093. time = time % 3600;
  4094. min = time / 60;
  4095. time = time % 60;
  4096. sec = time;
  4097. if (hour > 0) {
  4098. char temp[10];
  4099. snprintf(temp, 9," %i", hour);
  4100. time_msg.append(temp);
  4101. time_msg.append(" hour");
  4102. time_msg.append((hour > 1) ? "s" : "");
  4103. }
  4104. if (min > 0) {
  4105. char temp[5];
  4106. snprintf(temp, 4," %i", min);
  4107. time_msg.append(temp);
  4108. time_msg.append(" minute");
  4109. time_msg.append((min > 1) ? "s" : "");
  4110. }
  4111. // Only add seconds if minutes and hours are 0
  4112. if (hour == 0 && min == 0 && sec > 0) {
  4113. char temp[5];
  4114. snprintf(temp, 4," %i", sec);
  4115. time_msg.append(temp);
  4116. time_msg.append(" second");
  4117. time_msg.append((sec > 1) ? "s" : "");
  4118. }
  4119. if(displayClient)
  4120. Message(CHANNEL_COLOR_YELLOW, "You may not enter again for%s.", time_msg.c_str());
  4121. return time_msg;
  4122. }
  4123. }
  4124. }
  4125. return std::string("");
  4126. }
  4127. ZoneServer* Client::IdentifyInstance(int32 zoneID) {
  4128. int8 instanceType = database.GetInstanceTypeByZoneID(zoneID);
  4129. if(instanceType < 1)
  4130. return nullptr;
  4131. ZoneServer* instance_zone = nullptr;
  4132. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  4133. if (data) {
  4134. std::string lockoutTime = IdentifyInstanceLockout(zoneID);
  4135. // If lockout instances check to see if we are locked out
  4136. if (lockoutTime.length() > 0) {
  4137. return nullptr;
  4138. }
  4139. // Need to update `character_instances` table with new timestamps (for persistent) and instance id's
  4140. instance_zone = zone_list.GetByInstanceID(data->instance_id, zoneID, false, false);
  4141. // if we got an instance_zone and the instance_id from the data is 0 or data instance id is not the same as the zone instance id then update values
  4142. if (instance_zone && (data->instance_id == 0 || data->instance_id != instance_zone->GetInstanceID())) {
  4143. if (instanceType == SOLO_PERSIST_INSTANCE || instanceType == GROUP_PERSIST_INSTANCE || instanceType == RAID_PERSIST_INSTANCE) {
  4144. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  4145. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  4146. }
  4147. else
  4148. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID());
  4149. data->instance_id = instance_zone->GetInstanceID();
  4150. }
  4151. }
  4152. return instance_zone;
  4153. }
  4154. bool Client::TryZoneInstance(int32 zoneID, bool zone_coords_valid) {
  4155. ZoneServer* instance_zone = NULL;
  4156. int8 instanceType = 0;
  4157. // determine if this is a group instanced zone that already exists
  4158. instance_zone = GetPlayer()->GetGroupMemberInZone(zoneID);
  4159. if (instance_zone != NULL)
  4160. Zone(instance_zone->GetInstanceID(), zone_coords_valid);
  4161. else if ((instanceType = database.GetInstanceTypeByZoneID(zoneID)) > 0)
  4162. {
  4163. // best to check if we already have our own instance!
  4164. if((instance_zone = IdentifyInstance(zoneID)) == nullptr)
  4165. {
  4166. switch (instanceType)
  4167. {
  4168. case SOLO_LOCKOUT_INSTANCE:
  4169. case GROUP_LOCKOUT_INSTANCE:
  4170. case RAID_LOCKOUT_INSTANCE:
  4171. {
  4172. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4173. if (instance_zone) {
  4174. // once lockout instance zone shuts down you can't renenter if you have a lockout or if you don't you get a new zone
  4175. // so delete `instances` entry for the zone when it shuts down.
  4176. int32 db_id = database.AddCharacterInstance(GetPlayer()->GetCharacterID(), instance_zone->GetInstanceID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceType(), 0, 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime());
  4177. if (db_id > 0)
  4178. GetPlayer()->GetCharacterInstances()->AddInstance(db_id, instance_zone->GetInstanceID(), 0, 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime(), zoneID, instance_zone->GetInstanceType(), string(instance_zone->GetZoneName()));
  4179. }
  4180. break;
  4181. }
  4182. case SOLO_PERSIST_INSTANCE:
  4183. case GROUP_PERSIST_INSTANCE:
  4184. case RAID_PERSIST_INSTANCE:
  4185. {
  4186. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4187. if (instance_zone) {
  4188. int32 db_id = database.AddCharacterInstance(GetPlayer()->GetCharacterID(), instance_zone->GetInstanceID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceType(), Timer::GetUnixTimeStamp(), 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime());
  4189. if (db_id > 0)
  4190. GetPlayer()->GetCharacterInstances()->AddInstance(db_id, instance_zone->GetInstanceID(), Timer::GetUnixTimeStamp(), 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime(), zoneID, instance_zone->GetInstanceType(), string(instance_zone->GetZoneName()));
  4191. }
  4192. break;
  4193. }
  4194. case PUBLIC_INSTANCE:
  4195. case TRADESKILL_INSTANCE:
  4196. {
  4197. // if its public/tradeskill, look for a public already setup
  4198. instance_zone = zone_list.GetByLowestPopulation(zoneID);
  4199. if (instance_zone) {
  4200. // Check the current population against the max population, if greater or equal start a new version
  4201. if (instance_zone->GetClientCount() >= rule_manager.GetGlobalRule(R_Zone, MaxPlayers)->GetInt32())
  4202. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4203. }
  4204. else
  4205. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4206. break;
  4207. }
  4208. case PERSONAL_HOUSE_INSTANCE:
  4209. case GUILD_HOUSE_INSTANCE:
  4210. {
  4211. // Because of the way housing works (need to load a specific instance id supplied in a packet) we can't
  4212. // use this function without some rework, so it will all be handled in Client::HandlePacket()
  4213. // with the OP_EnterHouseMsg opcode
  4214. break;
  4215. }
  4216. case QUEST_INSTANCE:
  4217. {
  4218. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4219. break;
  4220. /*
  4221. ALTER TABLE `zones` CHANGE COLUMN `instance_type` `instance_type` ENUM('NONE','GROUP_LOCKOUT_INSTANCE','GROUP_PERSIST_INSTANCE','RAID_LOCKOUT_INSTANCE','RAID_PERSIST_INSTANCE','SOLO_LOCKOUT_INSTANCE','SOLO_PERSIST_INSTANCE','TRADESKILL_INSTANCE','PUBLIC_INSTANCE','PERSONAL_HOUSE_INSTANCE','GUILD_HOUSE_INSTANCE','QUEST_INSTANCE') NOT NULL DEFAULT 'NONE' COLLATE 'latin1_general_ci' AFTER `start_zone`;
  4222. */
  4223. }
  4224. default:
  4225. {
  4226. // NONE
  4227. }
  4228. }
  4229. }
  4230. if (instance_zone != NULL)
  4231. Zone(instance_zone, zone_coords_valid);
  4232. }
  4233. if (instance_zone != NULL)
  4234. return true;
  4235. else
  4236. return false;
  4237. }
  4238. bool Client::GotoSpawn(const char* search_name, bool forceTarget) {
  4239. Spawn* target = 0;
  4240. if (search_name || GetPlayer()->GetTarget()) {
  4241. Client* search_client = 0;
  4242. if (search_name) {
  4243. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  4244. if (!target) {
  4245. search_client = zone_list.GetClientByCharName(search_name);
  4246. if (search_client)
  4247. target = search_client->GetPlayer();
  4248. }
  4249. if (target)
  4250. GetPlayer()->SetTarget(target);
  4251. }
  4252. else
  4253. target = GetPlayer()->GetTarget();
  4254. float y = (target != nullptr) ? target->GetY() : 0.0f;
  4255. if(target && target->GetMap() != GetPlayer()->GetMap()) {
  4256. auto loc = glm::vec3(target->GetX(), target->GetZ(), target->GetY());
  4257. y = GetPlayer()->FindBestZ(loc, nullptr);
  4258. }
  4259. if (target && target != GetPlayer()) {
  4260. GetPlayer()->SetX(target->GetX());
  4261. GetPlayer()->SetY(y);
  4262. GetPlayer()->SetZ(target->GetZ());
  4263. GetPlayer()->SetHeading(target->GetHeading());
  4264. GetPlayer()->SetLocation(target->GetLocation());
  4265. Message(CHANNEL_COLOR_YELLOW, "Warping to '%s'", target->GetName());
  4266. }
  4267. else if (target)
  4268. Message(CHANNEL_COLOR_RED, "Error: You cannot goto yourself!");
  4269. if (search_client && search_client->GetCurrentZone() != GetCurrentZone())
  4270. Zone(search_client->GetCurrentZone()->GetZoneName(), false);
  4271. else if (target) {
  4272. EQ2Packet* app = GetPlayer()->Move(target->GetX(), y, target->GetZ(), GetVersion(), (target->GetHeading() + 180.0f));
  4273. if (app)
  4274. QueuePacket(app);
  4275. }
  4276. }
  4277. if (!target)
  4278. return false;
  4279. else
  4280. return true;
  4281. }
  4282. bool Client::CheckZoneAccess(const char* zoneName) {
  4283. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone access check for %s (%u), client: %u", zoneName, database.GetZoneID(zoneName), GetVersion());
  4284. ZoneServer* zone = zone_list.Get(zoneName, false, false, false);
  4285. // JA: implemented /zone lock|unlock commands (2012.07.28)
  4286. if (zone && zone->GetZoneLockState())
  4287. {
  4288. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone currently LOCKED: '%s' (%ul)", zoneName, zone->GetZoneID());
  4289. Message(CHANNEL_COLOR_RED, "This zone is locked, and you don't have the key! (%s).", zoneName);
  4290. return false;
  4291. }
  4292. sint16 zoneMinStatus = 0;
  4293. int16 zoneMinLevel = 0;
  4294. int16 zoneMaxLevel = 0;
  4295. int16 zoneMinVersion = 0;
  4296. if (!zone)
  4297. {
  4298. LogWrite(CCLIENT__DEBUG, 0, "Client", "Grabbing zone requirements for %s", zoneName);
  4299. bool success = database.GetZoneRequirements(zoneName, &zoneMinStatus, &zoneMinLevel, &zoneMaxLevel, &zoneMinVersion);
  4300. if (!success) { // couldn't even find the zone, this shouldn't happen though..
  4301. return true;
  4302. }
  4303. }
  4304. else
  4305. {
  4306. zoneMinStatus = zone->GetMinimumStatus();
  4307. zoneMinLevel = zone->GetMinimumLevel();
  4308. zoneMaxLevel = zone->GetMaximumLevel();
  4309. zoneMinVersion = zone->GetMinimumVersion();
  4310. }
  4311. LogWrite(CCLIENT__DEBUG, 0, "Client", "Access Requirements: status %i, level %i - %i, req >= %i version", zoneMinStatus, zoneMinLevel, zoneMaxLevel, zoneMinVersion);
  4312. // use ZoneLevelOverrideStatus in both min_level and max_level checks
  4313. sint16 ZoneLevelOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneLevelOverrideStatus)->GetSInt16();
  4314. if ((zoneMinVersion > 0) && (GetVersion() < zoneMinVersion))
  4315. {
  4316. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinVersion of %i challenge...", zoneMinVersion);
  4317. Message(CHANNEL_COLOR_RED, "You do not have the required expansion pack to enter here (%s).", database.GetExpansionIDByVersion(zoneMinVersion).c_str());
  4318. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client denied access to zone '%s' (version req: %i)", zoneName, zoneMinVersion);
  4319. return false;
  4320. }
  4321. if ((zoneMinLevel > 1) && (player->GetLevel() < zoneMinLevel))
  4322. {
  4323. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  4324. {
  4325. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  4326. Message(CHANNEL_COLOR_RED, "Your level is too low to enter here (%s)", zoneMinLevel);
  4327. return false;
  4328. }
  4329. }
  4330. if ((zoneMaxLevel > 1) && (player->GetLevel() > zoneMaxLevel))
  4331. {
  4332. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  4333. {
  4334. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  4335. Message(CHANNEL_COLOR_RED, "Your level is too high to enter here (%s)", zoneMaxLevel);
  4336. return false;
  4337. }
  4338. }
  4339. if ((zoneMinStatus > 0) && (GetAdminStatus() < zoneMinStatus))
  4340. {
  4341. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinStatus of %i challenge...", zoneMinStatus);
  4342. sint16 ZoneAccessOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneAccessOverrideStatus)->GetSInt16();
  4343. if (ZoneAccessOverrideStatus && ZoneAccessOverrideStatus > GetAdminStatus())
  4344. {
  4345. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (status req: %i)", zoneName, GetAdminStatus());
  4346. Message(CHANNEL_COLOR_RED, "You do not have permission to enter here (%i).", zoneMinStatus);
  4347. return false;
  4348. }
  4349. }
  4350. return true;
  4351. }
  4352. void Client::Zone(int32 instanceid, bool set_coords, bool byInstanceID, bool is_spell) {
  4353. Zone(zone_list.GetByInstanceID(instanceid, 0, false, true), set_coords, is_spell);
  4354. }
  4355. void Client::Zone(ZoneServer* new_zone, bool set_coords, bool is_spell) {
  4356. if (!new_zone) {
  4357. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request Denied! No 'new_zone' value");
  4358. return;
  4359. }
  4360. if(GetVersion() == 373 && GetAdminStatus() == 0) {
  4361. if(strncasecmp(new_zone->GetZoneFile(),"boat_06p_tutorial02",19) && strncasecmp(new_zone->GetZoneFile(),"tutorial_island02",17)) {
  4362. SimpleMessage(CHANNEL_COLOR_RED, "This client does not currently support beyond the boat tutorial (farjourneyfreeport) or island of refuge (islerefuge1)");
  4363. return;
  4364. }
  4365. }
  4366. client_zoning = true;
  4367. zoning_id = new_zone->GetZoneID();
  4368. zoning_instance_id = new_zone->GetInstanceID();
  4369. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting player Resurrecting to 'true'", __FUNCTION__);
  4370. player->SetResurrecting(true);
  4371. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from fighting...", __FUNCTION__);
  4372. //GetCurrentZone()->GetCombat()->RemoveHate(player);
  4373. SaveSpells();
  4374. ResetSendMail();
  4375. // Remove players pet from zone if there is one
  4376. ((Entity*)player)->DismissAllPets();
  4377. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from current zone...", __FUNCTION__);
  4378. GetCurrentZone()->RemoveSpawn(player, false, true, true, true, !is_spell);
  4379. GetPlayer()->DeleteSpellEffects(true);
  4380. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting zone to '%s'...", __FUNCTION__, new_zone->GetZoneName());
  4381. SetZoningDestination(new_zone);
  4382. SetCurrentZone(new_zone);
  4383. if (player->GetGroupMemberInfo())
  4384. {
  4385. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Player in group, updating group info...", __FUNCTION__);
  4386. player->UpdateGroupMemberInfo();
  4387. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id, this);
  4388. }
  4389. // block out the member info for the group
  4390. TempRemoveGroup();
  4391. UpdateTimeStampFlag(ZONE_UPDATE_FLAG);
  4392. if (set_coords)
  4393. {
  4394. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Zoning player to coordinates x: %2f, y: %2f, z: %2f, heading: %2f in zone '%s'...",
  4395. __FUNCTION__,
  4396. GetCurrentZone()->GetSafeX(),
  4397. GetCurrentZone()->GetSafeY(),
  4398. GetCurrentZone()->GetSafeZ(),
  4399. GetCurrentZone()->GetSafeHeading(),
  4400. new_zone->GetZoneName()
  4401. );
  4402. player->SetX(GetCurrentZone()->GetSafeX());
  4403. player->SetY(GetCurrentZone()->GetSafeY());
  4404. player->SetZ(GetCurrentZone()->GetSafeZ());
  4405. player->SetHeading(GetCurrentZone()->GetSafeHeading());
  4406. SetZoningCoords(GetCurrentZone()->GetSafeX(), GetCurrentZone()->GetSafeY(),
  4407. GetCurrentZone()->GetSafeZ(), GetCurrentZone()->GetSafeHeading());
  4408. }
  4409. else {
  4410. ResetZoningCoords();
  4411. }
  4412. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Saving Player info...", __FUNCTION__);
  4413. Save();
  4414. char* new_zone_ip = 0;
  4415. if (IsPrivateAddress(this->GetIP()) && strlen(net.GetInternalWorldAddress()) > 0)
  4416. new_zone_ip = net.GetInternalWorldAddress();
  4417. else
  4418. new_zone_ip = net.GetWorldAddress();
  4419. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: New Zone IP '%s'...", __FUNCTION__, new_zone_ip);
  4420. int32 key = Timer::GetUnixTimeStamp();
  4421. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending ZoneChangeMsg...", __FUNCTION__);
  4422. ClientPacketFunctions::SendZoneChange(this, new_zone_ip, net.GetWorldPort(), key);
  4423. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending to zone_auth.AddAuth...", __FUNCTION__);
  4424. zone_auth.AddAuth(new ZoneAuthRequest(GetAccountID(), player->GetName(), key));
  4425. if (version > 373) {
  4426. PacketStruct* packet = configReader.getStruct("WS_CancelMoveObjectMode", version);
  4427. if (packet)
  4428. {
  4429. QueuePacket(packet->serialize());
  4430. safe_delete(packet);
  4431. }
  4432. }
  4433. }
  4434. void Client::Zone(const char* new_zone, bool set_coords, bool is_spell)
  4435. {
  4436. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request to '%s'", new_zone);
  4437. Zone(zone_list.Get(new_zone), set_coords, is_spell);
  4438. }
  4439. float Client::DistanceFrom(Client* client) {
  4440. float ret = 0;
  4441. if (client && client != this) {
  4442. ret = pow(player->GetX() - client->player->GetX(), 2) + pow(player->GetY() - client->player->GetY(), 2) + pow(player->GetZ() - client->player->GetZ(), 2);
  4443. ret = sqrt(ret);
  4444. }
  4445. return ret;
  4446. }
  4447. void Client::DetermineCharacterUpdates() {
  4448. ServerPacket* outpack = new ServerPacket(ServerOP_BasicCharUpdate, sizeof(CharDataUpdate_Struct));
  4449. CharDataUpdate_Struct* cdu = (CharDataUpdate_Struct*)outpack->pBuffer;
  4450. cdu->account_id = GetAccountID();
  4451. cdu->char_id = GetCharacterID();
  4452. int32 timestamp = Timer::GetUnixTimeStamp();
  4453. int8 flag = GetTimeStampFlag();
  4454. if (flag & LEVEL_UPDATE_FLAG)
  4455. {
  4456. cdu->update_field = LEVEL_UPDATE_FLAG;
  4457. cdu->update_data = player->GetLevel();
  4458. loginserver.SendPacket(outpack);
  4459. }
  4460. //if(flag&CLASS_UPDATE_FLAG && player->GetLevel() >= 20)// Perseverance only
  4461. if (flag & CLASS_UPDATE_FLAG)
  4462. {
  4463. cdu->update_field = CLASS_UPDATE_FLAG;
  4464. cdu->update_data = player->GetAdventureClass();
  4465. loginserver.SendPacket(outpack);
  4466. }
  4467. if (flag & GENDER_UPDATE_FLAG)
  4468. {
  4469. cdu->update_field = GENDER_UPDATE_FLAG;
  4470. cdu->update_data = player->GetGender();
  4471. loginserver.SendPacket(outpack);
  4472. }
  4473. if (flag & DELETE_UPDATE_FLAG) {
  4474. LogWrite(MISC__TODO, 1, "TODO", "Delete update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  4475. }
  4476. safe_delete(outpack); // Zone, armor and name use a different structure
  4477. if (flag & RACE_UPDATE_FLAG)
  4478. {
  4479. outpack = new ServerPacket(ServerOP_RaceUpdate, sizeof(RaceUpdate_Struct));
  4480. RaceUpdate_Struct* ru = (RaceUpdate_Struct*)outpack->pBuffer;
  4481. ru->account_id = GetAccountID();
  4482. ru->char_id = GetCharacterID();
  4483. ru->race = player->GetRace();
  4484. ru->model_type = player->GetModelType();
  4485. loginserver.SendPacket(outpack);
  4486. safe_delete(outpack);
  4487. }
  4488. if (flag & ZONE_UPDATE_FLAG) {
  4489. ServerPacket* outpack = new ServerPacket(ServerOP_ZoneUpdate, CHARZONESTRUCT_MAXSIZE);
  4490. memset(outpack->pBuffer, 0, CHARZONESTRUCT_MAXSIZE);
  4491. CharZoneUpdate_Struct* czu = (CharZoneUpdate_Struct*)outpack->pBuffer;
  4492. czu->account_id = GetAccountID();
  4493. czu->char_id = GetCharacterID();
  4494. czu->zone_id = GetCurrentZone()->GetZoneID();
  4495. const char* zone_file = GetCurrentZone()->GetZoneFile();
  4496. czu->zone_length = strlen(zone_file);
  4497. if (czu->zone_length > 64)
  4498. czu->zone_length = 64;
  4499. strncpy(czu->new_zone, zone_file, czu->zone_length);
  4500. loginserver.SendPacket(outpack);
  4501. safe_delete(outpack);
  4502. }
  4503. if (flag & ARMOR_UPDATE_FLAG) {
  4504. LogWrite(MISC__TODO, 1, "TODO", "Armor update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  4505. }
  4506. if (flag & NAME_UPDATE_FLAG) {
  4507. LogWrite(MISC__TODO, 1, "TODO", "Name update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  4508. }
  4509. database.UpdateCharacterTimeStamp(GetAccountID(), GetCharacterID(), timestamp);
  4510. }
  4511. void Client::Save() {
  4512. if (GetCharacterID() == 0 || IsSaveDisabled())
  4513. return;
  4514. if (current_zone) {
  4515. DetermineCharacterUpdates();
  4516. UpdateCharacterInstances();
  4517. this->SetLastSavedTimeStamp(Timer::GetCurrentTime2());
  4518. database.Save(this);
  4519. if (GetPlayer()->UpdateQuickbarNeeded()) {
  4520. database.SaveQuickBar(GetCharacterID(), GetPlayer()->GetQuickbar());
  4521. GetPlayer()->ResetQuickbarNeeded();
  4522. }
  4523. database.SaveItems(this);
  4524. database.SaveBuyBacks(this);
  4525. GetPlayer()->SaveHistory();
  4526. GetPlayer()->SaveLUAHistory();
  4527. MSaveSpellStateMutex.lock();
  4528. GetPlayer()->SaveSpellEffects();
  4529. MSaveSpellStateMutex.unlock();
  4530. }
  4531. }
  4532. void Client::UpdateCharacterInstances() {
  4533. if (GetPlayer() != NULL)
  4534. GetPlayer()->GetCharacterInstances()->ProcessInstanceTimers(GetPlayer());
  4535. /*if ( GetPlayer() != NULL )
  4536. {
  4537. // determine the last timestamp then get a new one, determine the difference in the timestamp
  4538. // to use for applying the update to each instances timer
  4539. int32 lastSaveTS = GetLastSavedTimeStamp();
  4540. int32 newSaveTS = Timer::GetUnixTimeStamp();
  4541. int32 diffTS = newSaveTS - lastSaveTS;
  4542. // update instance timers
  4543. GetPlayer()->GetCharacterInstances().ProcessInstanceTimers(GetPlayer(),diffTS);
  4544. // update with the new timestamp and save the db
  4545. this->SetLastSavedTimeStamp(newSaveTS);
  4546. }*/
  4547. }
  4548. void Client::HandleVerbRequest(EQApplicationPacket* app) {
  4549. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsRequest", GetVersion());
  4550. if (packet) {
  4551. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  4552. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  4553. PacketStruct* out = configReader.getStruct("WS_EntityVerbsResponse", GetVersion());
  4554. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(spawn_id);
  4555. vector<EntityCommand*> commands;
  4556. vector<EntityCommand*> delete_commands;
  4557. if (out && spawn) {
  4558. for (int32 i = 0; i < spawn->primary_command_list.size(); i++)
  4559. {
  4560. // default is a deny list not allow, only allow if on the iterator list and itr second is not false (deny)
  4561. if (!spawn->primary_command_list[i]->default_allow_list)
  4562. {
  4563. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  4564. if (itr == spawn->primary_command_list[i]->allow_or_deny.end() || !itr->second)
  4565. continue;
  4566. }
  4567. else
  4568. {
  4569. // default is allow list, only deny if added to the list as deny (false itr second)
  4570. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  4571. if (itr != spawn->primary_command_list[i]->allow_or_deny.end() && !itr->second)
  4572. continue;
  4573. }
  4574. commands.push_back(spawn->primary_command_list[i]);
  4575. }
  4576. for (int32 i = 0; i < spawn->secondary_command_list.size(); i++)
  4577. commands.push_back(spawn->secondary_command_list[i]);
  4578. if (spawn->IsPlayer()) {
  4579. if (player->IsFriend(spawn->GetName()))
  4580. delete_commands.push_back(player->CreateEntityCommand("remove from friends list", 10000, "friend_remove", "", 0, 0));
  4581. else
  4582. delete_commands.push_back(player->CreateEntityCommand("add to friends list", 10000, "friend_add", "", 0, 0));
  4583. if (player->IsIgnored(spawn->GetName()))
  4584. delete_commands.push_back(player->CreateEntityCommand("remove from ignore list", 10000, "ignore_remove", "", 0, 0));
  4585. else
  4586. {
  4587. delete_commands.push_back(player->CreateEntityCommand("add to ignore list", 10000, "ignore_add", "", 0, 0));
  4588. delete_commands.push_back(player->CreateEntityCommand("Trade", 10, "start_trade", "", 0, 0));
  4589. }
  4590. if (((Player*)spawn)->GetGroupMemberInfo()) {
  4591. if (player->IsGroupMember((Player*)spawn) && player->GetGroupMemberInfo()->leader) { //group leader
  4592. delete_commands.push_back(player->CreateEntityCommand("kick from group", 10000, "kickfromgroup", "", 0, 0));
  4593. delete_commands.push_back(player->CreateEntityCommand("make group leader", 10000, "makeleader", "", 0, 0));
  4594. }
  4595. if(spawn->IsPlayer() && player->GetGroupMemberInfo() && !player->GetGroupMemberInfo()->mentor_target_char_id)
  4596. delete_commands.push_back(player->CreateEntityCommand("Mentor", 10000, "mentor", "", 0, 0));
  4597. else if(spawn->IsPlayer() && player->GetGroupMemberInfo() && player->GetGroupMemberInfo()->mentor_target_char_id == ((Player*)spawn)->GetCharacterID())
  4598. delete_commands.push_back(player->CreateEntityCommand("Stop Mentoring", 10000, "unmentor", "", 0, 0));
  4599. }
  4600. else if (!player->GetGroupMemberInfo() || (player->GetGroupMemberInfo()->leader && world.GetGroupManager()->GetGroupSize(player->GetGroupMemberInfo()->group_id) < 6))
  4601. delete_commands.push_back(player->CreateEntityCommand("invite to group", 10000, "invite", "", 0, 0));
  4602. commands.insert(commands.end(), delete_commands.begin(), delete_commands.end());
  4603. }
  4604. out->setDataByName("spawn_id", spawn_id);
  4605. out->setArrayLengthByName("num_verbs", commands.size());
  4606. for (int32 i = 0; i < commands.size(); i++) {
  4607. out->setArrayDataByName("command", commands[i]->command.c_str(), i);
  4608. out->setArrayDataByName("distance", commands[i]->distance, i);
  4609. if (commands[i]->error_text.length() == 0)
  4610. out->setArrayAddToPacketByName("error", false, i);
  4611. else {
  4612. out->setArrayDataByName("display_error", 1, i);
  4613. out->setArrayDataByName("error", commands[i]->error_text.c_str(), i);
  4614. }
  4615. out->setArrayDataByName("display_text", commands[i]->name.c_str(), i);
  4616. }
  4617. EQ2Packet* outapp = out->serialize();
  4618. //DumpPacket(outapp);
  4619. QueuePacket(outapp);
  4620. safe_delete(out);
  4621. for (int32 i = 0; i < delete_commands.size(); i++) {
  4622. safe_delete(delete_commands[i]);
  4623. }
  4624. }
  4625. }
  4626. safe_delete(packet);
  4627. }
  4628. }
  4629. void Client::SkillChanged(Skill* skill, int16 previous_value, int16 new_value) {
  4630. if (previous_value != new_value) {
  4631. 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);
  4632. char tmp[200] = { 0 };
  4633. 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);
  4634. SendPopupMessage(6, tmp, new_value > previous_value ? "skill_up" : "skill_down", 2.75f, 0xFF, 0xFF, 0xFF);
  4635. }
  4636. }
  4637. void Client::SendPopupMessage(int8 unknown, const char* text, const char* type, float size, int8 red, int8 green, int8 blue)
  4638. {
  4639. /* JA notes on the unknown:
  4640. 2 = ding glimmer
  4641. 16 = Achievement Unlocked
  4642. 6 no longer does anything
  4643. */
  4644. PacketStruct* packet = configReader.getStruct("WS_OnScreenMsg", GetVersion());
  4645. if (packet) {
  4646. packet->setDataByName("unknown", unknown);
  4647. packet->setMediumStringByName("text", text);
  4648. if (type && strlen(type) > 0)
  4649. packet->setMediumStringByName("message_type", type);
  4650. packet->setDataByName("size", size);
  4651. packet->setDataByName("red", red);
  4652. packet->setDataByName("green", green);
  4653. packet->setDataByName("blue", blue);
  4654. QueuePacket(packet->serialize());
  4655. safe_delete(packet);
  4656. }
  4657. }
  4658. void Client::ChangeLevel(int16 old_level, int16 new_level) {
  4659. if (new_level < 1) {
  4660. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  4661. return;
  4662. }
  4663. if (player->GetLevel() != new_level) {
  4664. player->SetLevel(new_level);
  4665. if (player->GetGroupMemberInfo()) {
  4666. player->UpdateGroupMemberInfo();
  4667. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  4668. }
  4669. }
  4670. if (new_level > old_level) {
  4671. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_ADVENTURE, new_level, player->GetAdventureClass());
  4672. }
  4673. if (player->GetPet()) {
  4674. NPC* pet = (NPC*)player->GetPet();
  4675. if (pet->GetMaxPetLevel() == 0 || new_level <= pet->GetMaxPetLevel()) {
  4676. pet->SetLevel(new_level);
  4677. pet->UpdateWeapons();
  4678. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4679. if (command_packet) {
  4680. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(pet));
  4681. command_packet->setDataByName("anim_type", 1753);
  4682. QueuePacket(command_packet->serialize());
  4683. safe_delete(command_packet);
  4684. }
  4685. }
  4686. }
  4687. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  4688. if (level_update) {
  4689. level_update->setDataByName("old_level", old_level);
  4690. level_update->setDataByName("new_level", new_level);
  4691. QueuePacket(level_update->serialize());
  4692. safe_delete(level_update);
  4693. GetCurrentZone()->StartZoneSpawnsForLevelThread(this);
  4694. GetCurrentZone()->SendCastSpellPacket(322, player, player); //send level up spell effect
  4695. //GetCurrentZone()->SendAllSpawnsForLevelChange(this);
  4696. }
  4697. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4698. if (command_packet) {
  4699. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  4700. command_packet->setDataByName("anim_type", 1753);
  4701. QueuePacket(command_packet->serialize());
  4702. safe_delete(command_packet);
  4703. }
  4704. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && new_level >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  4705. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  4706. SendNewAdventureSpells();
  4707. GetPlayer()->GetInfoStruct()->set_level(new_level);
  4708. GetPlayer()->UpdateWeapons();
  4709. // GetPlayer()->SetLevel(new_level);
  4710. 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__);
  4711. GetPlayer()->CalculatePlayerHPPower();
  4712. GetPlayer()->CalculateBonuses();
  4713. GetPlayer()->SetHP(GetPlayer()->GetTotalHP());
  4714. GetPlayer()->SetPower(GetPlayer()->GetTotalPower());
  4715. /*InfoStruct* info = player->GetInfoStruct();
  4716. info->set_agi_base(new_level * 2 + 15);
  4717. info->set_intel_base(new_level * 2 + 15);
  4718. info->set_wis_base(new_level * 2 + 15);
  4719. info->set_str_base(new_level * 2 + 15);
  4720. info->set_sta_base(new_level * 2 + 15);
  4721. info->set_cold_base((int16)(new_level * 1.5 + 10));
  4722. info->set_heat_base((int16)(new_level * 1.5 + 10));
  4723. info->set_disease_base((int16)(new_level * 1.5 + 10));
  4724. info->set_mental_base((int16)(new_level * 1.5 + 10));
  4725. info->set_magic_base((int16)(new_level * 1.5 + 10));
  4726. info->set_divine_base((int16)(new_level * 1.5 + 10));
  4727. info->set_poison_base((int16)(new_level * 1.5 + 10));
  4728. GetPlayer()->GetInfoStruct()->set_poison_base((int16)(new_level * 1.5 + 10));*/
  4729. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  4730. GetPlayer()->SetCharSheetChanged(true);
  4731. Message(CHANNEL_REWARD, "You are now level %i!", new_level);
  4732. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  4733. int16 new_skill_cap = 5 * new_level;
  4734. PlayerSkillList* player_skills = player->GetSkills();
  4735. player_skills->SetSkillCapsByType(SKILL_TYPE_ARMOR, new_skill_cap);
  4736. player_skills->SetSkillCapsByType(SKILL_TYPE_SHIELD, new_skill_cap);
  4737. if(rule_manager.GetGlobalRule(R_Player, AutoSkillUpBaseSkills)->GetBool()) {
  4738. //SKILL_TYPE_ARMOR/SKILL_TYPE_SHIELD always has the same current / max values
  4739. player_skills->SetSkillValuesByType(SKILL_TYPE_ARMOR, new_skill_cap, false);
  4740. player_skills->SetSkillValuesByType(SKILL_TYPE_SHIELD, new_skill_cap, false);
  4741. }
  4742. player_skills->SetSkillCapsByType(SKILL_TYPE_CLASS, new_skill_cap);
  4743. player_skills->SetSkillCapsByType(SKILL_TYPE_WEAPON, new_skill_cap);
  4744. if(rule_manager.GetGlobalRule(R_Player, AutoSkillUpBaseSkills)->GetBool()) {
  4745. //SKILL_TYPE_CLASS/SKILL_TYPE_WEAPON always has the same current/max values
  4746. player_skills->SetSkillValuesByType(SKILL_TYPE_CLASS, new_skill_cap, false);
  4747. player_skills->SetSkillValuesByType(SKILL_TYPE_WEAPON, new_skill_cap, false);
  4748. }
  4749. player_skills->SetSkillCapsByType(SKILL_TYPE_COMBAT, new_skill_cap);
  4750. player_skills->SetSkillCapsByType(SKILL_TYPE_GENERAL, new_skill_cap);
  4751. player_skills->SetSkillCapsByType(SKILL_TYPE_SPELLCASTING, new_skill_cap);
  4752. player_skills->SetSkillCapsByType(SKILL_TYPE_AVOIDANCE, new_skill_cap);
  4753. player_skills->SetSkillCapsByType(SKILL_TYPE_WEAPONRY, new_skill_cap);
  4754. if (new_level > player->GetTSLevel())
  4755. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, new_skill_cap);
  4756. //SKILL_ID_DUALWIELD, SKILL_ID_FISTS, SKILL_ID_DESTROYING, and SKILL_ID_MAGIC_AFFINITY always have the current_val equal to max_val
  4757. if (player_skills->HasSkill(SKILL_ID_DUALWIELD))
  4758. player_skills->SetSkill(SKILL_ID_DUALWIELD, new_skill_cap);
  4759. if (player_skills->HasSkill(SKILL_ID_FISTS))
  4760. player_skills->SetSkill(SKILL_ID_FISTS, new_skill_cap);
  4761. if (player_skills->HasSkill(SKILL_ID_DESTROYING))
  4762. player_skills->SetSkill(SKILL_ID_DESTROYING, new_skill_cap);
  4763. if (player_skills->HasSkill(SKILL_ID_MAGIC_AFFINITY))
  4764. player_skills->SetSkill(SKILL_ID_MAGIC_AFFINITY, new_skill_cap);
  4765. Guild* guild = GetPlayer()->GetGuild();
  4766. if (guild) {
  4767. int8 event_type = 0;
  4768. if (new_level < 10)
  4769. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_1_10;
  4770. else if (new_level == 10)
  4771. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_10;
  4772. else if (new_level >= 11 && new_level < 20)
  4773. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_11_20;
  4774. else if (new_level == 20)
  4775. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_20;
  4776. else if (new_level >= 21 && new_level < 30)
  4777. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_21_30;
  4778. else if (new_level == 30)
  4779. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_30;
  4780. else if (new_level >= 31 && new_level < 40)
  4781. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_31_40;
  4782. else if (new_level == 40)
  4783. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_40;
  4784. else if (new_level >= 41 && new_level < 50)
  4785. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_41_50;
  4786. else if (new_level == 50)
  4787. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_50;
  4788. else if (new_level >= 51 && new_level < 60)
  4789. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_51_60;
  4790. else if (new_level == 60)
  4791. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_60;
  4792. else if (new_level >= 61 && new_level < 70)
  4793. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_61_70;
  4794. else if (new_level == 70)
  4795. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_70;
  4796. else if (new_level >= 71 && new_level < 80)
  4797. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_71_80;
  4798. else if (new_level == 80)
  4799. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_80;
  4800. 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());
  4801. 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());
  4802. guild->UpdateGuildMemberInfo(GetPlayer());
  4803. guild->SendGuildMember(GetPlayer());
  4804. guild->SendGuildMemberList();
  4805. }
  4806. // Need to send the trait list every time the players level changes
  4807. // Also need to force the char sheet update or else there can be a large delay from when you level
  4808. // to when you are actually able to select traits.
  4809. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  4810. GetPlayer()->need_trait_update = true;
  4811. if (version > 561) {
  4812. QueuePacket(master_trait_list.GetTraitListPacket(this));
  4813. master_aa_list.DisplayAA(this, 0, 0);
  4814. }
  4815. else
  4816. master_trait_list.ChooseNextTrait(this);
  4817. if (GetPlayer()->SpawnedBots.size() > 0) {
  4818. map<int32, int32>::iterator itr;
  4819. for (itr = GetPlayer()->SpawnedBots.begin(); itr != GetPlayer()->SpawnedBots.end(); itr++) {
  4820. Spawn* bot = GetCurrentZone()->GetSpawnByID(itr->second);
  4821. if (bot && bot->IsBot())
  4822. ((Bot*)bot)->ChangeLevel(old_level, new_level);
  4823. }
  4824. }
  4825. if (GetPlayer()->GetHP() < GetPlayer()->GetTotalHP() || GetPlayer()->GetPower() < GetPlayer()->GetTotalPower())
  4826. GetPlayer()->GetZone()->AddDamagedSpawn(GetPlayer());
  4827. }
  4828. void Client::ChangeTSLevel(int16 old_level, int16 new_level) {
  4829. if (new_level < 1) {
  4830. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  4831. return;
  4832. }
  4833. if ((player->GetTSLevel() >= 9 && player->GetTradeskillClass() == 1) || (player->GetTSLevel() >= 19 && (player->GetTradeskillClass() == 1 || player->GetTradeskillClass() == 2 || player->GetTradeskillClass() == 6 || player->GetTradeskillClass() == 10))) {
  4834. SimpleMessage(CHANNEL_COLOR_YELLOW, "You can not gain levels until you select your next class!");
  4835. return;
  4836. }
  4837. if (new_level > old_level)
  4838. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_TRADESKILL, new_level, player->GetTradeskillClass());
  4839. if (player->GetTSLevel() != new_level) {
  4840. player->SetTSLevel(new_level);
  4841. if (player->GetGroupMemberInfo()) {
  4842. player->UpdateGroupMemberInfo();
  4843. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  4844. }
  4845. }
  4846. // Only tradeskill skills should increace, and then only those related to your class
  4847. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  4848. if (level_update) {
  4849. level_update->setDataByName("old_level", old_level);
  4850. level_update->setDataByName("new_level", new_level);
  4851. level_update->setDataByName("type", 1);
  4852. QueuePacket(level_update->serialize());
  4853. safe_delete(level_update);
  4854. }
  4855. // provide new spells upon levelling
  4856. SendNewTradeskillSpells();
  4857. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4858. if (command_packet) {
  4859. command_packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  4860. command_packet->setDataByName("anim_type", 1753);
  4861. QueuePacket(command_packet->serialize());
  4862. safe_delete(command_packet);
  4863. }
  4864. GetPlayer()->GetInfoStruct()->set_tradeskill_level(new_level);
  4865. GetPlayer()->SetTSLevel(new_level);
  4866. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  4867. GetPlayer()->SetCharSheetChanged(true);
  4868. Message(CHANNEL_NARRATIVE, "Your tradeskill level is now %i!", new_level);
  4869. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  4870. PlayerSkillList* player_skills = player->GetSkills();
  4871. int16 specialize_skill_cap = new_level * 5;
  4872. int16 artisan_skill_cap = std::max<int16>(specialize_skill_cap, 49);
  4873. int16 specialize_10_skill_cap = std::max<int16>(specialize_skill_cap, 99);
  4874. int8 ts_class = player->GetTradeskillClass();
  4875. int8 base_ts_class = classes.GetSecondaryTSBaseClass(ts_class);
  4876. int32 skill_id_1, skill_id_2, skill_id_3;
  4877. switch (base_ts_class) {
  4878. case ARTISAN:
  4879. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4880. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4881. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4882. break;
  4883. case OUTFITTER:
  4884. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4885. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4886. skill_id_1 = SKILL_ID_TAILORING;
  4887. skill_id_2 = SKILL_ID_METALSHAPING;
  4888. skill_id_3 = SKILL_ID_METALWORKING;
  4889. if (ts_class == TAILOR) {
  4890. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4891. skill_id_1 = 0;
  4892. }
  4893. else if (ts_class == ARMORER) {
  4894. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4895. skill_id_2 = 0;
  4896. }
  4897. else if (ts_class == WEAPONSMITH) {
  4898. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4899. skill_id_3 = 0;
  4900. }
  4901. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4902. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4903. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4904. break;
  4905. case SCHOLAR:
  4906. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4907. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4908. skill_id_1 = SKILL_ID_SCRIBING;
  4909. skill_id_2 = SKILL_ID_CHEMISTRY;
  4910. skill_id_3 = SKILL_ID_ARTIFICING;
  4911. if (ts_class == SAGE) {
  4912. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4913. skill_id_1 = 0;
  4914. }
  4915. else if (ts_class == ALCHEMIST) {
  4916. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4917. skill_id_2 = 0;
  4918. }
  4919. else if (ts_class == JEWELER) {
  4920. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4921. skill_id_3 = 0;
  4922. }
  4923. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4924. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4925. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4926. break;
  4927. case CRAFTSMAN:
  4928. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4929. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4930. skill_id_1 = SKILL_ID_ARTISTRY;
  4931. skill_id_2 = SKILL_ID_FLETCHING;
  4932. skill_id_3 = SKILL_ID_SCULPTING;
  4933. if (ts_class == PROVISIONER) {
  4934. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4935. skill_id_1 = 0;
  4936. }
  4937. else if (ts_class == WOODWORKER) {
  4938. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4939. skill_id_2 = 0;
  4940. }
  4941. else if (ts_class == CARPENTER) {
  4942. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4943. skill_id_3 = 0;
  4944. }
  4945. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4946. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4947. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4948. break;
  4949. default:
  4950. break;
  4951. }
  4952. if (new_level > player->GetAdventureClass())
  4953. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, specialize_skill_cap);
  4954. Guild* guild = GetPlayer()->GetGuild();
  4955. if (guild) {
  4956. int8 event_type = 0;
  4957. if (new_level < 10)
  4958. event_type = GUILD_EVENT_GAINS_TS_LEVEL_1_10;
  4959. else if (new_level == 10)
  4960. event_type = GUILD_EVENT_GAINS_TS_LEVEL_10;
  4961. else if (new_level >= 11 && new_level < 20)
  4962. event_type = GUILD_EVENT_GAINS_TS_LEVEL_11_20;
  4963. else if (new_level == 20)
  4964. event_type = GUILD_EVENT_GAINS_TS_LEVEL_20;
  4965. else if (new_level >= 21 && new_level < 30)
  4966. event_type = GUILD_EVENT_GAINS_TS_LEVEL_21_30;
  4967. else if (new_level == 30)
  4968. event_type = GUILD_EVENT_GAINS_TS_LEVEL_30;
  4969. else if (new_level >= 31 && new_level < 40)
  4970. event_type = GUILD_EVENT_GAINS_TS_LEVEL_31_40;
  4971. else if (new_level == 40)
  4972. event_type = GUILD_EVENT_GAINS_TS_LEVEL_40;
  4973. else if (new_level >= 41 && new_level < 50)
  4974. event_type = GUILD_EVENT_GAINS_TS_LEVEL_41_50;
  4975. else if (new_level == 50)
  4976. event_type = GUILD_EVENT_GAINS_TS_LEVEL_50;
  4977. else if (new_level >= 51 && new_level < 60)
  4978. event_type = GUILD_EVENT_GAINS_TS_LEVEL_51_60;
  4979. else if (new_level == 60)
  4980. event_type = GUILD_EVENT_GAINS_TS_LEVEL_60;
  4981. else if (new_level >= 61 && new_level < 70)
  4982. event_type = GUILD_EVENT_GAINS_TS_LEVEL_61_70;
  4983. else if (new_level == 70)
  4984. event_type = GUILD_EVENT_GAINS_TS_LEVEL_70;
  4985. else if (new_level >= 71 && new_level < 80)
  4986. event_type = GUILD_EVENT_GAINS_TS_LEVEL_71_80;
  4987. else if (new_level == 80)
  4988. event_type = GUILD_EVENT_GAINS_TS_LEVEL_80;
  4989. 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());
  4990. 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());
  4991. guild->UpdateGuildMemberInfo(GetPlayer());
  4992. guild->SendGuildMember(GetPlayer());
  4993. guild->SendGuildMemberList();
  4994. }
  4995. // Need to send the trait list every time the players level changes
  4996. // Also need to force the char sheet update or else there can be a large delay from when you level
  4997. // to when you are actually able to select traits.
  4998. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  4999. QueuePacket(master_trait_list.GetTraitListPacket(this));
  5000. }
  5001. void Client::CloseLoot(int32 spawn_id) {
  5002. if (GetVersion() > 561) {
  5003. PacketStruct* packet = configReader.getStruct("WS_CloseWindow", GetVersion());
  5004. if (packet) {
  5005. packet->setDataByName("window_id", 4);
  5006. EQ2Packet* outapp = packet->serialize();
  5007. if (outapp) {
  5008. //DumpPacket(outapp);
  5009. QueuePacket(outapp);
  5010. }
  5011. safe_delete(packet);
  5012. }
  5013. }
  5014. if(spawn_id > 0){
  5015. PacketStruct* packet = configReader.getStruct("WS_StoppedLooting", GetVersion());
  5016. if (packet) {
  5017. packet->setDataByName("spawn_id", spawn_id);
  5018. EQ2Packet* outapp = packet->serialize();
  5019. if (outapp)
  5020. QueuePacket(outapp);
  5021. safe_delete(packet);
  5022. }
  5023. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(spawn_id);
  5024. if(spawn) {
  5025. spawn->CloseLoot(GetPlayer());
  5026. }
  5027. }
  5028. }
  5029. string Client::GetCoinMessage(int32 total_coins) {
  5030. if (total_coins == 0) {
  5031. return " 0 Copper";
  5032. }
  5033. char tmp[64] = { 0 };
  5034. string message = "";
  5035. int32 val = 0;
  5036. if (total_coins >= 1000000) {
  5037. val = total_coins / 1000000;
  5038. total_coins -= 1000000 * val;
  5039. sprintf(tmp, " %u Platinum", val);
  5040. message.append(tmp);
  5041. memset(tmp, 0, 64);
  5042. }
  5043. if (total_coins >= 10000) {
  5044. val = total_coins / 10000;
  5045. total_coins -= 10000 * val;
  5046. sprintf(tmp, " %u Gold", val);
  5047. message.append(tmp);
  5048. memset(tmp, 0, 64);
  5049. }
  5050. if (total_coins >= 100) {
  5051. val = total_coins / 100;
  5052. total_coins -= 100 * val;
  5053. sprintf(tmp, " %u Silver", val);
  5054. message.append(tmp);
  5055. memset(tmp, 0, 64);
  5056. }
  5057. if (total_coins > 0) {
  5058. sprintf(tmp, " %u Copper", (int32)total_coins);
  5059. message.append(tmp);
  5060. }
  5061. return message;
  5062. }
  5063. void Client::SendLootResponsePacket(int32 total_coins, vector<Item*>* items, Spawn* entity, bool ignore_loot_tier) {
  5064. if (!entity) {
  5065. CloseLoot(0);
  5066. return;
  5067. }
  5068. if (total_coins > 0) {
  5069. player->AddCoins(total_coins);
  5070. //PlaySound("coin_cha_ching");
  5071. string message = "";
  5072. if (entity->GetHP() == 0) {
  5073. message = "You loot ";
  5074. entity->SetLootCoins(0, false);
  5075. }
  5076. else
  5077. message = "You receive ";
  5078. message.append(GetCoinMessage(total_coins));
  5079. if (entity->GetHP() == 0)
  5080. message.append(" from the corpse of ").append(entity->GetName());
  5081. int8 type = CHANNEL_LOOT;
  5082. SimpleMessage(type, message.c_str());
  5083. }
  5084. entity->StartLootTimer(GetPlayer());
  5085. PacketStruct* packet = configReader.getStruct("WS_UpdateLoot", GetVersion());
  5086. if (packet) {
  5087. entity->AddSpawnLootWindowCompleted(GetPlayer()->GetID(), false);
  5088. vector<Item*>::iterator itr;
  5089. int32 packet_size = 0;
  5090. EQ2Packet* outapp = 0;
  5091. uchar* data = 0;
  5092. vector<Item*> send_items;
  5093. if (items && items->size() > 0) {
  5094. for (int i = 0; i < items->size(); i++) {
  5095. Item* item = (*items)[i];
  5096. if (entity->GetLootMethod() > GroupLootMethod::METHOD_FFA && !ignore_loot_tier) {
  5097. bool skipItem = entity->IsItemInLootTier(item);
  5098. if (!skipItem) {
  5099. send_items.push_back(item);
  5100. }
  5101. }
  5102. else {
  5103. send_items.push_back(item);
  5104. }
  5105. }
  5106. }
  5107. if (GetVersion() >= 374) {
  5108. if (GetVersion() > 561) {
  5109. if (send_items.size() > 0) {
  5110. packet->setDataByName("loot_count", send_items.size());
  5111. packet->setDataByName("display", 1);
  5112. }
  5113. packet->setDataByName("loot_type", entity->GetLootMethod());
  5114. packet->setDataByName("lotto_timeout", entity->GetLootTimeRemaining() / 1000);
  5115. packet->setDataByName("loot_id", entity->GetID());
  5116. EQ2Packet* tmpPacket = packet->serialize();
  5117. packet_size += tmpPacket->size;
  5118. if (send_items.size() > 0) {
  5119. data = new uchar[send_items.size() * 1000 + packet_size];
  5120. memset(data, 0, send_items.size() * 1000 + packet_size);
  5121. }
  5122. else {
  5123. data = new uchar[packet_size];
  5124. memset(data, 0, packet_size);
  5125. }
  5126. uchar* ptr = data;
  5127. memcpy(ptr, tmpPacket->pBuffer, tmpPacket->size);
  5128. ptr += tmpPacket->size;
  5129. safe_delete(tmpPacket);
  5130. Item* item = 0;
  5131. if (send_items.size() > 0) {
  5132. for (itr = send_items.begin(); itr != send_items.end(); itr++) {
  5133. item = *itr;
  5134. memcpy(ptr, &item->details.item_id, sizeof(int32));
  5135. ptr += sizeof(int32);
  5136. packet_size += sizeof(int32);
  5137. tmpPacket = item->serialize(GetVersion(), true, GetPlayer(), false, 1, 0, false, true);
  5138. int8 offset = 0;
  5139. if (GetVersion() >= 1188) {
  5140. offset = 13;
  5141. }
  5142. else if (GetVersion() >= 860) {
  5143. offset = 11;
  5144. }
  5145. else if (GetVersion() <= 561) {
  5146. offset = 19;
  5147. }
  5148. else {
  5149. offset = 10;
  5150. }
  5151. memcpy(ptr, tmpPacket->pBuffer + offset, tmpPacket->size - offset);
  5152. ptr += tmpPacket->size - offset;
  5153. packet_size += tmpPacket->size - offset;
  5154. safe_delete(tmpPacket);
  5155. }
  5156. }
  5157. packet_size -= sizeof(int32);
  5158. memcpy(data, &packet_size, sizeof(int32));
  5159. packet_size += sizeof(int32);
  5160. outapp = new EQ2Packet(OP_ClientCmdMsg, data, packet_size);
  5161. }
  5162. else {
  5163. if (send_items.size() > 0) {
  5164. packet->setArrayLengthByName("loot_count", send_items.size());
  5165. Item* item = 0;
  5166. if (send_items.size() > 0) {
  5167. int i = 0;
  5168. for (itr = send_items.begin(); itr != send_items.end(); itr++) {
  5169. item = *itr;
  5170. packet->setArrayDataByName("loot_id", item->details.item_id, i);
  5171. packet->setItemArrayDataByName("item", item, GetPlayer(), i, 0, 2, true);
  5172. i++;
  5173. }
  5174. }
  5175. packet->setDataByName("display", 1);
  5176. }
  5177. packet->setDataByName("loot_type", entity->GetLootMethod()); // normal
  5178. packet->setDataByName("lotto_timeout", entity->GetLootTimeRemaining() / 1000); // 60 seconds
  5179. packet->setDataByName("spawn_id", entity->GetID());
  5180. outapp = packet->serialize();
  5181. }
  5182. }
  5183. else {
  5184. if (send_items.size() > 0) {
  5185. packet->setArrayLengthByName("loot_count", send_items.size());
  5186. for (int i = 0; i < send_items.size(); i++) {
  5187. Item* item = (send_items)[i];
  5188. packet->setArrayDataByName("name", item->name.c_str(), i);
  5189. packet->setArrayDataByName("item_id", item->details.item_id, i);
  5190. packet->setArrayDataByName("count", item->details.count, i);
  5191. packet->setArrayDataByName("icon", item->details.icon, i);
  5192. if (item->generic_info.skill_req1 > 0 && item->generic_info.skill_req1 < 0xFFFFFFFF)
  5193. packet->setArrayDataByName("ability_id", item->generic_info.skill_req1, i);
  5194. else if (item->generic_info.skill_req2 > 0 && item->generic_info.skill_req2 < 0xFFFFFFFF)
  5195. packet->setArrayDataByName("ability_id", item->generic_info.skill_req2, i);
  5196. else
  5197. packet->setArrayDataByName("ability_id", 0xFFFFFFFF, i);
  5198. }
  5199. }
  5200. packet->setDataByName("display", 1);
  5201. packet->setDataByName("loot_type", entity->GetLootMethod()); // normal
  5202. packet->setDataByName("lotto_timeout", entity->GetLootTimeRemaining() / 1000); // 60 seconds
  5203. packet->setDataByName("object_id", entity->GetID());
  5204. outapp = packet->serialize();
  5205. }
  5206. if (outapp) {
  5207. QueuePacket(outapp);
  5208. }
  5209. safe_delete_array(data);
  5210. safe_delete(packet);
  5211. if (!items || items->size() == 0)
  5212. CloseLoot(entity->GetID());
  5213. }
  5214. }
  5215. bool Client::LootSpawnByMethod(Spawn* entity) {
  5216. bool sentLoot = false;
  5217. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  5218. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  5219. if (gmi && gmi->group_id)
  5220. {
  5221. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  5222. if (group)
  5223. {
  5224. int8 auto_split_coin = group->GetGroupOptions()->auto_split;
  5225. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  5226. deque<GroupMemberInfo*>* members = group->GetMembers();
  5227. int32 split_coin_per_player = 0;
  5228. int32 coins_remain_after_split = entity->GetLootCoins();
  5229. int32 total_coins = entity->GetLootCoins();
  5230. if (auto_split_coin) {
  5231. int8 members_in_zone = 0;
  5232. for (int8 i = 0; i < members->size(); i++) {
  5233. Entity* member = members->at(i)->member;
  5234. if (!member || !member->IsPlayer())
  5235. continue;
  5236. if (member->GetZone() != GetPlayer()->GetZone())
  5237. continue;
  5238. members_in_zone++;
  5239. }
  5240. if (members_in_zone < 1) // this should not happen, but divide by zero checked
  5241. members_in_zone = 0;
  5242. split_coin_per_player = entity->GetLootCoins() / members_in_zone;
  5243. coins_remain_after_split = entity->GetLootCoins() - (split_coin_per_player * members_in_zone);
  5244. entity->SetLootCoins(0, false);
  5245. }
  5246. 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);
  5247. bool startWithLooter = true;
  5248. for (int8 i = 0; i < members->size(); i++) {
  5249. Entity* member = members->at(i)->member;
  5250. if (!member || !member->IsPlayer())
  5251. continue;
  5252. if (member->GetZone() != GetPlayer()->GetZone())
  5253. continue;
  5254. // this will make sure we properly send the loot window to the initial requester if there is no item rarity matches
  5255. if (startWithLooter && member != GetPlayer())
  5256. continue;
  5257. else if (!startWithLooter && member == GetPlayer())
  5258. continue;
  5259. else if (startWithLooter) {
  5260. i = 0;
  5261. startWithLooter = false;
  5262. }
  5263. if (auto_split_coin && (split_coin_per_player + coins_remain_after_split) > 0) {
  5264. player->AddCoins(split_coin_per_player + coins_remain_after_split);
  5265. if (((Player*)member)->GetClient()) {
  5266. ((Player*)member)->GetClient()->Message(CHANNEL_MONEY_SPLIT, "Your share of %s from the corpse of %s is %s.", GetCoinMessage(total_coins).c_str(), entity->GetLootName(), GetCoinMessage(split_coin_per_player + coins_remain_after_split).c_str());
  5267. }
  5268. if (coins_remain_after_split > 0) // overflow of coin division went to the first player
  5269. coins_remain_after_split = 0;
  5270. }
  5271. switch (entity->GetLootMethod()) {
  5272. case GroupLootMethod::METHOD_LOTTO:
  5273. case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
  5274. if (((Player*)member)->GetClient()) {
  5275. switch (member->GetInfoStruct()->get_group_auto_loot_method()) {
  5276. case 1: { // lotto, need
  5277. if (entity->GetLootMethod() == GroupLootMethod::METHOD_LOTTO) {
  5278. entity->AddLottoItemRequest(0xFFFFFFFF, GetPlayer()->GetID());
  5279. }
  5280. else { // *need* before greed
  5281. entity->AddNeedGreedItemRequest(0xFFFFFFFF, GetPlayer()->GetID(), true);
  5282. }
  5283. entity->AddSpawnLootWindowCompleted(member->GetID(), true);
  5284. // if it already exists we have to override the setting
  5285. entity->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
  5286. break;
  5287. }
  5288. case 2: { // decline
  5289. entity->AddSpawnLootWindowCompleted(member->GetID(), true);
  5290. // if it already exists we have to override the setting
  5291. entity->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
  5292. break;
  5293. }
  5294. default: { // presume 0 or higher than 2
  5295. ((Player*)member)->GetClient()->SendLootResponsePacket((!auto_split_coin && member == GetPlayer()) ? entity->GetLootCoins() : 0, entity->GetLootItems(), entity, true);
  5296. break;
  5297. }
  5298. }
  5299. sentLoot = true;
  5300. }
  5301. break;
  5302. }
  5303. case GroupLootMethod::METHOD_ROUND_ROBIN: {
  5304. entity->AddSpawnLootWindowCompleted(member->GetID(), true);
  5305. sentLoot = true;
  5306. break;
  5307. }
  5308. case GroupLootMethod::METHOD_LEADER: {
  5309. if (member->GetGroupMemberInfo()->leader)
  5310. ((Player*)member)->GetClient()->SendLootResponsePacket((!auto_split_coin && member == GetPlayer()) ? entity->GetLootCoins() : 0, entity->GetLootItems(), entity);
  5311. break;
  5312. }
  5313. case GroupLootMethod::METHOD_FFA: {
  5314. if(member == GetPlayer()) {
  5315. ((Player*)member)->GetClient()->SendLootResponsePacket((!auto_split_coin && member == GetPlayer()) ? entity->GetLootCoins() : 0, entity->GetLootItems(), entity);
  5316. }
  5317. break;
  5318. }
  5319. }
  5320. }
  5321. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  5322. }
  5323. }
  5324. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  5325. return sentLoot;
  5326. }
  5327. void Client::LootSpawnRequest(Spawn* entity, bool attemptDisarm) {
  5328. bool lootAllowed = false;
  5329. bool sentLoot = false;
  5330. std::vector<int32> item_list;
  5331. if (entity->IsNPC()) {
  5332. entity->LockLoot();
  5333. lootAllowed = ((NPC*)entity)->Brain()->CheckLootAllowed(GetPlayer());
  5334. entity->UnlockLoot();
  5335. if (lootAllowed) {
  5336. OpenChest(entity, attemptDisarm);
  5337. }
  5338. else {
  5339. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not allowed to loot at this time.");
  5340. return;
  5341. }
  5342. entity->LockLoot();
  5343. if (((NPC*)entity)->Brain()->CheckLootAllowed(GetPlayer())) {
  5344. lootAllowed = true;
  5345. if ((sentLoot = LootSpawnByMethod(entity))) {
  5346. entity->GetLootItemsList(&item_list);
  5347. }
  5348. else {
  5349. SendLootResponsePacket(entity->GetLootCoins(), entity->GetLootItems(), entity);
  5350. }
  5351. }
  5352. entity->UnlockLoot();
  5353. if (lootAllowed) {
  5354. entity->DistributeGroupLoot_RoundRobin(&item_list, true);
  5355. }
  5356. }
  5357. }
  5358. void Client::OpenChest(Spawn* entity, bool attemptDisarm)
  5359. {
  5360. if (!entity)
  5361. return;
  5362. int8 chest_difficulty = 0;
  5363. int32 state = 0;
  5364. // Check for the chest and set the action state
  5365. /*4034 = small chest | 5864 = treasure chest | 5865 = ornate treasure chest | 4015 = exquisite chest*/
  5366. string modelName;
  5367. if (entity->GetModelType() == 4034) {
  5368. // small chest, open with copper coins
  5369. // does not include traps, however can be disarmed
  5370. chest_difficulty = 1;
  5371. state = 11899;
  5372. modelName.append("Small Chest");
  5373. }
  5374. else if (entity->GetModelType() == 5864) {
  5375. // treasure chest, open with silver coins
  5376. chest_difficulty = 2;
  5377. state = 11901;
  5378. modelName.append("Treasure Chest");
  5379. }
  5380. else if (entity->GetModelType() == 5865) {
  5381. // ornate chest, open with gold coins
  5382. chest_difficulty = 3;
  5383. state = 11900;
  5384. modelName.append("Ornate Chest");
  5385. }
  5386. else if (entity->GetModelType() == 4015) {
  5387. // exquisite chest, open with gold coins and jewels as well as a glow effect
  5388. chest_difficulty = 5;
  5389. state = 11898;
  5390. modelName.append("Exquisite Chest");
  5391. }
  5392. bool firstChestOpen = false;
  5393. if (chest_difficulty > 0 && !entity->HasTrapTriggered())
  5394. {
  5395. ChestTrap::ChestTrapInfo nextTrap;
  5396. bool ret = chest_trap_list.GetNextTrap(GetCurrentZone()->GetZoneID(), chest_difficulty, &nextTrap);
  5397. Skill* disarmSkill = GetPlayer()->GetSkillByName("Disarm Trap", false);
  5398. firstChestOpen = true;
  5399. entity->SetTrapTriggered(true, state);
  5400. if (ret)
  5401. {
  5402. if (disarmSkill && attemptDisarm)
  5403. {
  5404. if (disarmSkill->CheckDisarmSkill(entity->GetLevel(), chest_difficulty) < 1)
  5405. {
  5406. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  5407. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  5408. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  5409. }
  5410. else
  5411. {
  5412. Message(CHANNEL_NARRATIVE, "You disarm the trap on %s", modelName.c_str());
  5413. }
  5414. // despite fail/succeed we should always try to increase skill if disarm is available
  5415. GetPlayer()->GetSkillByName("Disarm Trap", true);
  5416. }
  5417. else // no disarm skill, always fail
  5418. {
  5419. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  5420. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  5421. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  5422. }
  5423. }
  5424. }
  5425. else if (!entity->HasTrapTriggered())
  5426. {
  5427. firstChestOpen = true;
  5428. entity->SetTrapTriggered(true, state);
  5429. }
  5430. // We set the visual state with out updating so those not in range will see it opened when it is finally sent to them,
  5431. // for those in range the SendStateCommand will cause it to animate open.
  5432. // players not currently in radius will have it queued with client->QueueStateCommand when SendSpawn takes place
  5433. if (firstChestOpen)
  5434. GetCurrentZone()->SendStateCommand(entity, state);
  5435. }
  5436. void Client::CastGroupOrSelf(Entity* source, uint32 spellID, uint32 spellTier, float restrictiveRadius)
  5437. {
  5438. Spell* spell = master_spell_list.GetSpell(spellID, spellTier);
  5439. SpellProcess* spellProcess = GetCurrentZone()->GetSpellProcess();
  5440. if (source == NULL)
  5441. source = (Entity*)GetPlayer();
  5442. if (spell)
  5443. {
  5444. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  5445. if (gmi && gmi->group_id)
  5446. {
  5447. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  5448. if (group)
  5449. {
  5450. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  5451. deque<GroupMemberInfo*>* members = group->GetMembers();
  5452. for (int8 i = 0; i < members->size(); i++) {
  5453. Entity* member = members->at(i)->member;
  5454. if(!member)
  5455. continue;
  5456. if (!member->Alive() || (member->GetZone() != source->GetZone()))
  5457. continue;
  5458. // if we have a radius provided then check if the group member is outside the radius or not
  5459. if (restrictiveRadius > 0.0f && member->GetDistance(source) > restrictiveRadius)
  5460. continue;
  5461. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  5462. }
  5463. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  5464. }
  5465. }
  5466. else
  5467. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  5468. }
  5469. }
  5470. Spawn* Client::GetBanker() {
  5471. return banker;
  5472. }
  5473. void Client::SetBanker(Spawn* in_banker) {
  5474. banker = in_banker;
  5475. }
  5476. void Client::Bank(Spawn* banker, bool cancel) {
  5477. if (banker && banker->primary_command_list.size() > 0 && banker->primary_command_list[0]->command == "bank") {
  5478. if (!cancel)
  5479. SetBanker(banker);
  5480. else
  5481. SetBanker(0);
  5482. PacketStruct* packet = configReader.getStruct("WS_UpdateBank", GetVersion());
  5483. if (packet) {
  5484. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(banker));
  5485. int64 coins = GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + GetPlayer()->GetInfoStruct()->get_bank_coin_silver() * 100 +
  5486. GetPlayer()->GetInfoStruct()->get_bank_coin_gold() * 10000 + (int64)GetPlayer()->GetInfoStruct()->get_bank_coin_plat() * 1000000;
  5487. int32 coins1, coins2;
  5488. coins1 = ((int32*)&coins)[0];
  5489. coins2 = ((int32*)&coins)[1];
  5490. packet->setDataByName("bank_coins", coins1);
  5491. packet->setDataByName("bank_coins2", coins2);
  5492. packet->setDataByName("copper", GetPlayer()->GetInfoStruct()->get_coin_copper());
  5493. packet->setDataByName("silver", GetPlayer()->GetInfoStruct()->get_coin_silver());
  5494. packet->setDataByName("gold", GetPlayer()->GetInfoStruct()->get_coin_gold());
  5495. packet->setDataByName("plat", GetPlayer()->GetInfoStruct()->get_coin_plat());
  5496. if (!cancel)
  5497. packet->setDataByName("display", 1);
  5498. QueuePacket(packet->serialize());
  5499. safe_delete(packet);
  5500. }
  5501. }
  5502. }
  5503. bool Client::BankHasCoin(int64 amount){
  5504. int32 tmp = 0;
  5505. if(amount <= 0)
  5506. return 0;
  5507. //plat
  5508. if (amount >= 1000000) {
  5509. tmp = amount / 1000000;
  5510. int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
  5511. if(bank_coins_plat >= tmp)
  5512. return 1;
  5513. }
  5514. //gold
  5515. if (amount >= 10000) {
  5516. tmp = amount / 10000;
  5517. int32 bank_coins_gold = GetPlayer()->GetBankCoinsGold();
  5518. if(bank_coins_gold >= tmp)
  5519. return 1;
  5520. }
  5521. //silver
  5522. if (amount >= 100) {
  5523. tmp = amount / 100;
  5524. int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
  5525. if(bank_coins_silver >= tmp)
  5526. return 1;
  5527. }
  5528. //copper
  5529. if (amount > 0) {
  5530. int32 bank_coins_copper = GetPlayer()->GetBankCoinsCopper();
  5531. if(bank_coins_copper >= amount)
  5532. return 1;
  5533. }
  5534. return 0;
  5535. }
  5536. bool Client::BankWithdrawalNoBanker(int64 amount) {
  5537. bool cheater = false;
  5538. if (amount > 0) {
  5539. string withdrawal = "";
  5540. char withdrawal_data[512] = { 0 };
  5541. int32 tmp = 0;
  5542. if (amount >= 1000000) {
  5543. tmp = amount / 1000000;
  5544. int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
  5545. if (tmp > bank_coins_plat)
  5546. cheater = true;
  5547. else {
  5548. GetPlayer()->GetInfoStruct()->set_bank_coin_plat(bank_coins_plat - tmp);
  5549. GetPlayer()->GetInfoStruct()->add_coin_plat(tmp);
  5550. amount -= (int64)tmp * 1000000;
  5551. sprintf(withdrawal_data, "%u Platinum ", tmp);
  5552. withdrawal.append(withdrawal_data);
  5553. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5554. }
  5555. }
  5556. if (!cheater && amount >= 10000) {
  5557. tmp = amount / 10000;
  5558. if (tmp > GetPlayer()->GetBankCoinsGold())
  5559. cheater = true;
  5560. else {
  5561. int32 bank_coins_gold = GetPlayer()->GetInfoStruct()->get_bank_coin_gold();
  5562. bank_coins_gold -= tmp;
  5563. if ((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) > 100) {
  5564. GetPlayer()->GetInfoStruct()->set_coin_gold((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) - 100);
  5565. GetPlayer()->GetInfoStruct()->add_coin_plat(1);
  5566. }
  5567. else
  5568. GetPlayer()->GetInfoStruct()->add_coin_gold(tmp);
  5569. amount -= tmp * 10000;
  5570. sprintf(withdrawal_data, "%u Gold ", tmp);
  5571. withdrawal.append(withdrawal_data);
  5572. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5573. }
  5574. }
  5575. if (!cheater && amount >= 100) {
  5576. tmp = amount / 100;
  5577. int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
  5578. if (tmp > bank_coins_silver)
  5579. cheater = true;
  5580. else {
  5581. GetPlayer()->GetInfoStruct()->set_bank_coin_silver(bank_coins_silver - tmp);
  5582. if ((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) > 100) {
  5583. GetPlayer()->GetInfoStruct()->set_coin_silver((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) - 100);
  5584. GetPlayer()->GetInfoStruct()->add_coin_gold(1);
  5585. }
  5586. else
  5587. GetPlayer()->GetInfoStruct()->add_coin_silver(tmp);
  5588. amount -= tmp * 100;
  5589. sprintf(withdrawal_data, "%u Silver ", tmp);
  5590. withdrawal.append(withdrawal_data);
  5591. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5592. }
  5593. }
  5594. if (!cheater) {
  5595. if (amount > 0) {
  5596. sprintf(withdrawal_data, "%u Copper ", (int32)amount);
  5597. withdrawal.append(withdrawal_data);
  5598. int32 bank_coin_copper = GetPlayer()->GetInfoStruct()->get_bank_coin_copper();
  5599. GetPlayer()->GetInfoStruct()->set_bank_coin_copper(bank_coin_copper - amount);
  5600. if ((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) > 100) {
  5601. GetPlayer()->GetInfoStruct()->set_coin_copper((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) - 100);
  5602. GetPlayer()->GetInfoStruct()->add_coin_silver(1);
  5603. }
  5604. else
  5605. GetPlayer()->GetInfoStruct()->add_coin_copper(amount);
  5606. }
  5607. if (withdrawal.length() > 0) {
  5608. withdrawal.append("withdrawn ");
  5609. sprintf(withdrawal_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  5610. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  5611. withdrawal.append(withdrawal_data);
  5612. SimpleMessage(CHANNEL_NARRATIVE, withdrawal.c_str());
  5613. return 1;
  5614. }
  5615. }
  5616. else
  5617. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  5618. return 0;
  5619. }
  5620. return 0;
  5621. }
  5622. void Client::BankWithdrawal(int64 amount) {
  5623. bool cheater = false;
  5624. if (GetBanker() && amount > 0) {
  5625. string withdrawal = "";
  5626. char withdrawal_data[512] = { 0 };
  5627. int32 tmp = 0;
  5628. if (amount >= 1000000) {
  5629. tmp = amount / 1000000;
  5630. int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
  5631. if (tmp > bank_coins_plat)
  5632. cheater = true;
  5633. else {
  5634. GetPlayer()->GetInfoStruct()->set_bank_coin_plat(bank_coins_plat - tmp);
  5635. GetPlayer()->GetInfoStruct()->add_coin_plat(tmp);
  5636. amount -= (int64)tmp * 1000000;
  5637. sprintf(withdrawal_data, "%u Platinum ", tmp);
  5638. withdrawal.append(withdrawal_data);
  5639. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5640. }
  5641. }
  5642. if (!cheater && amount >= 10000) {
  5643. tmp = amount / 10000;
  5644. if (tmp > GetPlayer()->GetBankCoinsGold())
  5645. cheater = true;
  5646. else {
  5647. int32 bank_coins_gold = GetPlayer()->GetInfoStruct()->get_bank_coin_gold();
  5648. bank_coins_gold -= tmp;
  5649. if ((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) > 100) {
  5650. GetPlayer()->GetInfoStruct()->set_coin_gold((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) - 100);
  5651. GetPlayer()->GetInfoStruct()->add_coin_plat(1);
  5652. }
  5653. else
  5654. GetPlayer()->GetInfoStruct()->add_coin_gold(tmp);
  5655. amount -= tmp * 10000;
  5656. sprintf(withdrawal_data, "%u Gold ", tmp);
  5657. withdrawal.append(withdrawal_data);
  5658. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5659. }
  5660. }
  5661. if (!cheater && amount >= 100) {
  5662. tmp = amount / 100;
  5663. int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
  5664. if (tmp > bank_coins_silver)
  5665. cheater = true;
  5666. else {
  5667. GetPlayer()->GetInfoStruct()->set_bank_coin_silver(bank_coins_silver - tmp);
  5668. if ((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) > 100) {
  5669. GetPlayer()->GetInfoStruct()->set_coin_silver((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) - 100);
  5670. GetPlayer()->GetInfoStruct()->add_coin_gold(1);
  5671. }
  5672. else
  5673. GetPlayer()->GetInfoStruct()->add_coin_silver(tmp);
  5674. amount -= tmp * 100;
  5675. sprintf(withdrawal_data, "%u Silver ", tmp);
  5676. withdrawal.append(withdrawal_data);
  5677. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5678. }
  5679. }
  5680. if (!cheater) {
  5681. if (amount > 0) {
  5682. sprintf(withdrawal_data, "%u Copper ", (int32)amount);
  5683. withdrawal.append(withdrawal_data);
  5684. int32 bank_coin_copper = GetPlayer()->GetInfoStruct()->get_bank_coin_copper();
  5685. GetPlayer()->GetInfoStruct()->set_bank_coin_copper(bank_coin_copper - amount);
  5686. if ((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) > 100) {
  5687. GetPlayer()->GetInfoStruct()->set_coin_copper((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) - 100);
  5688. GetPlayer()->GetInfoStruct()->add_coin_silver(1);
  5689. }
  5690. else
  5691. GetPlayer()->GetInfoStruct()->add_coin_copper(amount);
  5692. }
  5693. if (withdrawal.length() > 0) {
  5694. withdrawal.append("withdrawn ");
  5695. sprintf(withdrawal_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  5696. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  5697. withdrawal.append(withdrawal_data);
  5698. SimpleMessage(CHANNEL_NARRATIVE, withdrawal.c_str());
  5699. }
  5700. }
  5701. else
  5702. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  5703. player->SetCharSheetChanged(true);
  5704. Bank(banker);
  5705. }
  5706. }
  5707. void Client::BankDeposit(int64 amount) {
  5708. bool cheater = false;
  5709. if (GetBanker() && amount > 0) {
  5710. int32 tmp = 0;
  5711. char deposit_data[512] = { 0 };
  5712. string deposit = "";
  5713. if (amount >= 1000000) {
  5714. tmp = amount / 1000000;
  5715. if (tmp > GetPlayer()->GetCoinsPlat())
  5716. cheater = true;
  5717. else {
  5718. GetPlayer()->GetInfoStruct()->add_bank_coin_plat(tmp);
  5719. GetPlayer()->GetInfoStruct()->set_coin_plat(GetPlayer()->GetInfoStruct()->get_coin_plat() - tmp);
  5720. amount -= (int64)tmp * 1000000;
  5721. sprintf(deposit_data, "%u Platinum ", tmp);
  5722. deposit.append(deposit_data);
  5723. memset(deposit_data, 0, sizeof(deposit_data));
  5724. }
  5725. }
  5726. if (!cheater && amount >= 10000) {
  5727. tmp = amount / 10000;
  5728. if (tmp > GetPlayer()->GetCoinsGold())
  5729. cheater = true;
  5730. else {
  5731. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_gold() + tmp) > 100) {
  5732. GetPlayer()->GetInfoStruct()->set_bank_coin_gold((GetPlayer()->GetInfoStruct()->get_bank_coin_gold() + tmp) - 100);
  5733. GetPlayer()->GetInfoStruct()->add_bank_coin_plat(1);
  5734. }
  5735. else
  5736. GetPlayer()->GetInfoStruct()->add_bank_coin_gold(tmp);
  5737. GetPlayer()->GetInfoStruct()->set_coin_gold(GetPlayer()->GetInfoStruct()->get_coin_gold() - tmp);
  5738. amount -= tmp * 10000;
  5739. sprintf(deposit_data, "%u Gold ", tmp);
  5740. deposit.append(deposit_data);
  5741. memset(deposit_data, 0, sizeof(deposit_data));
  5742. }
  5743. }
  5744. if (!cheater && amount >= 100) {
  5745. tmp = amount / 100;
  5746. if (tmp > GetPlayer()->GetCoinsSilver())
  5747. cheater = true;
  5748. else {
  5749. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_silver() + tmp) > 100) {
  5750. GetPlayer()->GetInfoStruct()->set_bank_coin_silver((GetPlayer()->GetInfoStruct()->get_bank_coin_silver() + tmp) - 100);
  5751. GetPlayer()->GetInfoStruct()->add_bank_coin_gold(1);
  5752. }
  5753. else
  5754. GetPlayer()->GetInfoStruct()->add_bank_coin_silver(tmp);
  5755. GetPlayer()->GetInfoStruct()->set_coin_silver(GetPlayer()->GetInfoStruct()->get_coin_silver() - tmp);
  5756. amount -= tmp * 100;
  5757. sprintf(deposit_data, "%u Silver ", tmp);
  5758. deposit.append(deposit_data);
  5759. memset(deposit_data, 0, sizeof(deposit_data));
  5760. }
  5761. }
  5762. if (!cheater) {
  5763. if (amount > 0) {
  5764. sprintf(deposit_data, "%u Copper ", (int32)amount);
  5765. deposit.append(deposit_data);
  5766. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + amount) > 100) {
  5767. GetPlayer()->GetInfoStruct()->set_bank_coin_copper((GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + amount) - 100);
  5768. GetPlayer()->GetInfoStruct()->add_bank_coin_silver(1);
  5769. }
  5770. else
  5771. GetPlayer()->GetInfoStruct()->add_bank_coin_copper(amount);
  5772. GetPlayer()->GetInfoStruct()->set_coin_copper(GetPlayer()->GetInfoStruct()->get_coin_copper() - amount);
  5773. }
  5774. if (deposit.length() > 0) {
  5775. deposit.append("deposited ");
  5776. sprintf(deposit_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  5777. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  5778. deposit.append(deposit_data);
  5779. SimpleMessage(CHANNEL_NARRATIVE, deposit.c_str());
  5780. }
  5781. }
  5782. else
  5783. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  5784. player->SetCharSheetChanged(true);
  5785. Bank(banker);
  5786. }
  5787. }
  5788. void Client::AddPendingQuestAcceptReward(Quest* quest)
  5789. {
  5790. std::unique_lock lock(MPendingQuestAccept);
  5791. pending_quest_accept.push_back(quest->GetQuestID());
  5792. }
  5793. void Client::AddPendingQuestReward(Quest* quest, bool update, bool is_temporary, std::string description) {
  5794. QueueQuestReward(quest->GetQuestID(), is_temporary, false, false, (is_temporary ? quest->GetCoinTmpReward() : 0),
  5795. (is_temporary ? quest->GetStatusTmpReward() : 0), description, false, 0);
  5796. quest_updates = update;
  5797. if(quest_updates) {
  5798. SaveQuestRewardData(true);
  5799. }
  5800. }
  5801. 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) {
  5802. if(HasQuestRewardQueued(quest_id, is_temporary, is_collection))
  5803. return;
  5804. QuestRewardData* data = new QuestRewardData;
  5805. data->quest_id = quest_id;
  5806. data->is_temporary = is_temporary;
  5807. data->is_collection = is_collection;
  5808. data->has_displayed = has_displayed;
  5809. data->tmp_coin = tmp_coin;
  5810. data->tmp_status = tmp_status;
  5811. data->description = std::string(description);
  5812. data->db_saved = db_saved;
  5813. data->db_index = index;
  5814. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5815. quest_pending_reward.push_back(data);
  5816. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5817. }
  5818. bool Client::HasQuestRewardQueued(int32 quest_id, bool is_temporary, bool is_collection) {
  5819. bool success = false;
  5820. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  5821. if (quest_pending_reward.size() > 0) {
  5822. vector<QuestRewardData*>::iterator itr;
  5823. for (itr = quest_pending_reward.begin(); itr != quest_pending_reward.end(); itr++) {
  5824. int32 questID = (*itr)->quest_id;
  5825. bool temporary = (*itr)->is_temporary;
  5826. bool collection = (*itr)->is_collection;
  5827. if( questID == quest_id && is_temporary == temporary && is_collection == collection ) {
  5828. success = true;
  5829. break;
  5830. }
  5831. }
  5832. }
  5833. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5834. return success;
  5835. }
  5836. void Client::RemoveQueuedQuestReward() {
  5837. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5838. if(quest_pending_reward.size() > 0) {
  5839. QuestRewardData* data = quest_pending_reward.at(0);
  5840. if(data->db_saved) {
  5841. Query query;
  5842. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete FROM character_quest_rewards where char_id = %u and indexed = %u", GetCharacterID(), data->db_index);
  5843. if(data->is_temporary && data->quest_id) {
  5844. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete FROM character_quest_temporary_rewards where char_id = %u and quest_id = %u", GetCharacterID(), data->quest_id);
  5845. }
  5846. }
  5847. quest_pending_reward.erase(quest_pending_reward.begin());
  5848. }
  5849. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5850. SaveQuestRewardData(true);
  5851. }
  5852. void Client::AddPendingQuestUpdate(int32 quest_id, int32 step_id, int32 progress) {
  5853. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5854. quest_pending_updates[quest_id][step_id] = progress;
  5855. quest_updates = true;
  5856. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5857. }
  5858. void Client::ProcessQuestUpdates() {
  5859. if(!IsReadyForUpdates())
  5860. return;
  5861. if (quest_pending_updates.size() > 0) {
  5862. map<int32, map<int32, int32> > tmp_quest_updates;
  5863. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5864. tmp_quest_updates.insert(quest_pending_updates.begin(), quest_pending_updates.end());
  5865. quest_pending_updates.clear();
  5866. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5867. map<int32, map<int32, int32> >::iterator quest_itr;
  5868. map<int32, int32>::iterator step_itr;
  5869. for (quest_itr = tmp_quest_updates.begin(); quest_itr != tmp_quest_updates.end(); quest_itr++) {
  5870. for (step_itr = quest_itr->second.begin(); step_itr != quest_itr->second.end(); step_itr++) {
  5871. if (step_itr->second == 0xFFFFFFFF) {
  5872. SetStepComplete(quest_itr->first, step_itr->first);
  5873. player->SendQuestRequiredSpawns(quest_itr->first);
  5874. }
  5875. else
  5876. AddStepProgress(quest_itr->first, step_itr->first, step_itr->second);
  5877. }
  5878. }
  5879. }
  5880. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  5881. if (quest_pending_reward.size() > 0) {
  5882. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5883. // only able to display one reward at a time
  5884. if(GetPlayer()->IsActiveReward())
  5885. return;
  5886. Query query;
  5887. vector<QuestRewardData*>::iterator itr;
  5888. vector<QuestRewardData*> tmp_quest_rewards;
  5889. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5890. tmp_quest_rewards.insert(tmp_quest_rewards.begin(), quest_pending_reward.begin(), quest_pending_reward.begin()+1);
  5891. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5892. bool delete_first = false;
  5893. for (itr = tmp_quest_rewards.begin(); itr != tmp_quest_rewards.end();) {
  5894. int32 questID = (*itr)->quest_id;
  5895. if((*itr)->is_collection && GetPlayer()->GetPendingCollectionReward()) {
  5896. DisplayCollectionComplete(GetPlayer()->GetPendingCollectionReward());
  5897. GetPlayer()->SetActiveReward(true);
  5898. (*itr)->has_displayed = true;
  5899. UpdateCharacterRewardData((*itr));
  5900. break;
  5901. }
  5902. else if(questID > 0 && GetPlayer()->UpdateQuestReward(questID, (*itr))) {
  5903. (*itr)->has_displayed = true;
  5904. UpdateCharacterRewardData((*itr));
  5905. // only able to display one reward at a time
  5906. break;
  5907. } else {
  5908. delete_first = true;
  5909. LogWrite(CCLIENT__ERROR, 0, "Client", "Quest ID %u missing for Player %s, deleting quest id from tmp_quest_rewards.", questID, GetPlayer()->GetName());
  5910. break;
  5911. }
  5912. }
  5913. if(delete_first) {
  5914. RemoveQueuedQuestReward();
  5915. }
  5916. } else {
  5917. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5918. }
  5919. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  5920. if (quest_pending_reward.size() > 0) {
  5921. quest_updates = true;
  5922. }
  5923. else {
  5924. quest_updates = false;
  5925. }
  5926. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5927. }
  5928. void Client::CheckQuestQueue() {
  5929. MQuestQueue.writelock();
  5930. last_update_time = 0;
  5931. vector<QueuedQuest*>::iterator itr;
  5932. for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
  5933. if(!GetPlayer()->SendQuestStepUpdate((*itr)->quest_id, (*itr)->step, (*itr)->display_quest_helper)) {
  5934. LogWrite(CCLIENT__ERROR, 0, "Client", "Queued Quest ID %u missing for Player %s, cannot send quest step update.", (*itr)->quest_id, GetPlayer()->GetName());
  5935. }
  5936. safe_delete((*itr));
  5937. }
  5938. quest_queue.clear();
  5939. MQuestQueue.releasewritelock();
  5940. }
  5941. void Client::SetStepComplete(int32 quest_id, int32 step) {
  5942. Quest* quest = player->SetStepComplete(quest_id, step);
  5943. if (quest) {
  5944. SendQuestUpdate(quest);
  5945. GetCurrentZone()->SendQuestUpdates(this);
  5946. }
  5947. }
  5948. void Client::AddStepProgress(int32 quest_id, int32 step, int32 progress) {
  5949. Quest* quest = player->AddStepProgress(quest_id, step, progress);
  5950. if (quest) {
  5951. SendQuestUpdate(quest);
  5952. GetCurrentZone()->SendQuestUpdates(this);
  5953. }
  5954. }
  5955. void Client::CheckPlayerQuestsKillUpdate(Spawn* spawn) {
  5956. bool hadUpdates = false;
  5957. vector<Quest*>* quest_updates = player->CheckQuestsKillUpdate(spawn);
  5958. if (quest_updates) {
  5959. for (int32 i = 0; i < quest_updates->size(); i++)
  5960. {
  5961. SendQuestUpdate(quest_updates->at(i));
  5962. hadUpdates = true;
  5963. }
  5964. }
  5965. safe_delete(quest_updates);
  5966. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  5967. if (quest_failures) {
  5968. for (int32 i = 0; i < quest_failures->size(); i++)
  5969. {
  5970. SendQuestFailure(quest_failures->at(i));
  5971. hadUpdates = true;
  5972. }
  5973. }
  5974. safe_delete(quest_failures);
  5975. if (hadUpdates)
  5976. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  5977. }
  5978. void Client::CheckPlayerQuestsChatUpdate(Spawn* spawn) {
  5979. vector<Quest*>* quest_updates = player->CheckQuestsChatUpdate(spawn);
  5980. if (quest_updates) {
  5981. for (int32 i = 0; i < quest_updates->size(); i++)
  5982. SendQuestUpdate(quest_updates->at(i));
  5983. GetCurrentZone()->SendQuestUpdates(this);
  5984. }
  5985. safe_delete(quest_updates);
  5986. }
  5987. void Client::CheckPlayerQuestsItemUpdate(Item* item) {
  5988. vector<Quest*>* quest_updates = player->CheckQuestsItemUpdate(item);
  5989. if (quest_updates) {
  5990. for (int32 i = 0; i < quest_updates->size(); i++)
  5991. SendQuestUpdate(quest_updates->at(i));
  5992. }
  5993. safe_delete(quest_updates);
  5994. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  5995. if (quest_failures) {
  5996. for (int32 i = 0; i < quest_failures->size(); i++)
  5997. SendQuestFailure(quest_failures->at(i));
  5998. }
  5999. safe_delete(quest_failures);
  6000. }
  6001. void Client::CheckPlayerQuestsLocationUpdate() {
  6002. vector<Quest*>* quest_updates = player->CheckQuestsLocationUpdate();
  6003. if (quest_updates) {
  6004. for (int32 i = 0; i < quest_updates->size(); i++)
  6005. SendQuestUpdate(quest_updates->at(i));
  6006. }
  6007. safe_delete(quest_updates);
  6008. }
  6009. void Client::CheckPlayerQuestsSpellUpdate(Spell* spell) {
  6010. vector<Quest*>* quest_updates = player->CheckQuestsSpellUpdate(spell);
  6011. if (quest_updates) {
  6012. for (int32 i = 0; i < quest_updates->size(); i++)
  6013. SendQuestUpdate(quest_updates->at(i));
  6014. }
  6015. safe_delete(quest_updates);
  6016. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  6017. if (quest_failures) {
  6018. for (int32 i = 0; i < quest_failures->size(); i++)
  6019. SendQuestFailure(quest_failures->at(i));
  6020. }
  6021. safe_delete(quest_failures);
  6022. }
  6023. void Client::AddPendingQuest(Quest* quest, bool forced) {
  6024. if (version <= 372 || forced) { //this client doesn't ask if you want the quest, so auto accept
  6025. MPendingQuestAccept.lock();
  6026. player->pending_quests[quest->GetQuestID()] = quest;
  6027. MPendingQuestAccept.unlock();
  6028. AcceptQuest(quest->GetQuestID());
  6029. }
  6030. else {
  6031. MPendingQuestAccept.lock();
  6032. player->pending_quests[quest->GetQuestID()] = quest;
  6033. MPendingQuestAccept.unlock();
  6034. EQ2Packet* outapp = quest->OfferQuest(GetVersion(), player);
  6035. //DumpPacket(outapp);
  6036. QueuePacket(outapp);
  6037. }
  6038. }
  6039. void Client::AcceptQuest(int32 quest_id) {
  6040. MPendingQuestAccept.lock_shared();
  6041. if (player->pending_quests.count(quest_id) > 0) {
  6042. Quest* quest = player->pending_quests[quest_id];
  6043. if(quest) {
  6044. MPendingQuestAccept.unlock_shared();
  6045. MPendingQuestAccept.lock();
  6046. player->pending_quests.erase(quest->GetQuestID());
  6047. MPendingQuestAccept.unlock();
  6048. AddPlayerQuest(quest);
  6049. GetCurrentZone()->SendQuestUpdates(this);
  6050. GetPlayer()->UpdateQuestCompleteCount(quest_id);
  6051. return; // already unlocked mutex
  6052. }
  6053. }
  6054. MPendingQuestAccept.unlock_shared();
  6055. }
  6056. void Client::RemovePendingQuest(int32 quest_id) {
  6057. bool send_updates = false;
  6058. MPendingQuestAccept.lock_shared();
  6059. if (player->pending_quests.count(quest_id) > 0) {
  6060. Quest* quest = player->pending_quests[quest_id];
  6061. MPendingQuestAccept.unlock_shared();
  6062. MPendingQuestAccept.lock();
  6063. player->pending_quests.erase(quest_id);
  6064. MPendingQuestAccept.unlock();
  6065. if(lua_interface) {
  6066. lua_interface->CallQuestFunction(quest, "Declined", GetPlayer());
  6067. lua_interface->SetLuaUserDataStale(quest);
  6068. }
  6069. safe_delete(quest);
  6070. send_updates = true;
  6071. }
  6072. else {
  6073. MPendingQuestAccept.unlock_shared();
  6074. }
  6075. if(send_updates) {
  6076. GetCurrentZone()->SendQuestUpdates(this);
  6077. }
  6078. }
  6079. void Client::SetPlayerQuest(Quest* quest, map<int32, int32>* progress) {
  6080. if (!quest || !progress) {
  6081. return;
  6082. }
  6083. map<int32, int32>::iterator itr;
  6084. QuestStep* step = 0;
  6085. for (itr = progress->begin(); itr != progress->end(); itr++) {
  6086. step = quest->GetQuestStep(itr->first);
  6087. if (step && itr->second > 0) {
  6088. step->SetStepProgress(itr->second);
  6089. if (lua_interface && step->GetQuestCurrentQuantity() >= step->GetQuestNeededQuantity())
  6090. lua_interface->CallQuestFunction(quest, "Reload", player, step->GetStepID());
  6091. }
  6092. }
  6093. if (lua_interface && step)
  6094. lua_interface->CallQuestFunction(quest, "CurrentStep", player, step->GetStepID());
  6095. else if(!step) {
  6096. LogWrite(QUEST__ERROR, 0, "Client", "Missing step for quest %s (ID %u), cannot CallQuestFunction for CurrentStep", quest->GetName(), quest->GetQuestID());
  6097. }
  6098. }
  6099. void Client::AddPlayerQuest(Quest* quest, bool call_accepted, bool send_packets) {
  6100. bool lockCleared = false;
  6101. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  6102. if (player->player_quests.count(quest->GetQuestID()) > 0 && player->player_quests[quest->GetQuestID()]) {
  6103. if (player->player_quests[quest->GetQuestID()]->GetQuestFlags() > 0)
  6104. quest->SetQuestFlags(player->player_quests[quest->GetQuestID()]->GetQuestFlags());
  6105. int32 questID = quest->GetQuestID();
  6106. lockCleared = true;
  6107. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  6108. RemovePlayerQuest(questID, false, false);
  6109. }
  6110. player->player_quests[quest->GetQuestID()] = quest;
  6111. if(!lockCleared)
  6112. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  6113. quest->SetPlayer(player);
  6114. quest->SetSaveNeeded(true);
  6115. current_quest_id = quest->GetQuestID();
  6116. if (send_packets && quest->GetQuestGiver() > 0)
  6117. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  6118. if (lua_interface && call_accepted)
  6119. lua_interface->CallQuestFunction(quest, "Accepted", player);
  6120. if (send_packets) {
  6121. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6122. //SendQuestJournal();
  6123. SendQuestJournalUpdate(quest);
  6124. // sent twice to match live
  6125. quest->SetTracked(false);
  6126. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  6127. quest->SetTracked(true);
  6128. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  6129. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  6130. }
  6131. //This isn't during a load screen, so update spawns with required quests
  6132. if (call_accepted)
  6133. player->SendQuestRequiredSpawns(quest->GetQuestID());
  6134. }
  6135. void Client::RemovePlayerQuest(int32 id, bool send_update, bool delete_quest) {
  6136. if (current_quest_id == id)
  6137. current_quest_id = 0;
  6138. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  6139. if (player->player_quests.count(id) > 0 && player->player_quests[id]) {
  6140. if (delete_quest) {
  6141. player->player_quests[id]->SetDeleted(true);
  6142. database.DeleteCharacterQuest(id, GetCharacterID(), player->GetCompletedPlayerQuests()->count(id) > 0);
  6143. }
  6144. int32 quest_giver = player->player_quests[id]->GetQuestGiver();
  6145. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  6146. if (send_update && quest_giver > 0)
  6147. GetCurrentZone()->SendSpawnChangesByDBID(quest_giver, this, false, true);
  6148. if (send_update) {
  6149. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6150. SendQuestJournal(false, 0, true);
  6151. }
  6152. player->RemoveQuest(id, delete_quest);
  6153. if (send_update) {
  6154. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6155. SendQuestJournal(false, 0, true);
  6156. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  6157. }
  6158. }
  6159. else {
  6160. // if we don't have any quests to count then release the write lock
  6161. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  6162. }
  6163. }
  6164. void Client::SendQuestUpdateStepImmediately(Quest* quest, int32 step, bool display_quest_helper) {
  6165. if (quest) {
  6166. QuestStep* quest_step = quest->GetQuestStep(step);
  6167. if (quest_step) {
  6168. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, quest_step, 1, false, false, display_quest_helper));
  6169. quest_step->WasUpdated(false);
  6170. }
  6171. }
  6172. }
  6173. void Client::SendQuestUpdateStep(Quest* quest, int32 step, bool display_quest_helper) {
  6174. QueuedQuest* item = new QueuedQuest;
  6175. item->quest_id = quest->GetQuestID();
  6176. item->step = step;
  6177. item->display_quest_helper = display_quest_helper;
  6178. MQuestQueue.writelock();
  6179. quest_queue.push_back(item);
  6180. last_update_time = Timer::GetCurrentTime2();
  6181. MQuestQueue.releasewritelock();
  6182. }
  6183. void Client::SendQuestFailure(Quest* quest) {
  6184. vector<QuestStep*>* failures = quest->GetQuestFailures();
  6185. if (failures) {
  6186. QuestStep* step = 0;
  6187. for (int32 i = 0; i < failures->size(); i++) {
  6188. step = failures->at(i);
  6189. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step, 1, false, true));
  6190. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6191. SendQuestJournal(false, 0, true);
  6192. }
  6193. failures->clear();
  6194. }
  6195. }
  6196. void Client::SendQuestUpdate(Quest* quest) {
  6197. vector<QuestStep*>* updates = quest->GetQuestUpdates();
  6198. if (updates) {
  6199. QuestStep* step = 0;
  6200. bool updated = false;
  6201. for (int32 i = 0; i < updates->size(); i++) {
  6202. step = updates->at(i);
  6203. if (lua_interface && step->Complete() && quest->GetCompleteAction(step->GetStepID()))
  6204. {
  6205. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(step->GetStepID()), player);
  6206. SendQuestUpdateStep(quest, step->GetStepID());
  6207. updated = true;
  6208. }
  6209. if (step->WasUpdated()) {
  6210. // reversing the order of SendQuestJournal and QueuePacket QuestJournalReply causes AoM client to crash!
  6211. SendQuestJournal(false, 0, true);
  6212. if(!updated)
  6213. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step));
  6214. updated = true;
  6215. }
  6216. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6217. }
  6218. if (lua_interface && quest->GetCompleted() && quest->GetCompleteAction()) {
  6219. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(), player);
  6220. SendQuestJournalUpdate(quest, true);
  6221. }
  6222. if (quest->GetCompleted()) {
  6223. if (quest->GetQuestReturnNPC() > 0)
  6224. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestReturnNPC(), this, false, true);
  6225. if (quest->GetCompletedFlag())
  6226. quest->SetCompletedFlag(false);
  6227. }
  6228. updates->clear();
  6229. }
  6230. }
  6231. void Client::SendQuestJournal(bool all_quests, Client* client, bool updated) {
  6232. if (!client)
  6233. client = this;
  6234. PacketStruct* packet = player->GetQuestJournalPacket(all_quests, GetVersion(), GetNameCRC(), current_quest_id, updated);
  6235. if (packet) {
  6236. EQ2Packet* outapp = packet->serialize();
  6237. //DumpPacket(outapp);
  6238. client->QueuePacket(outapp);
  6239. safe_delete(packet);
  6240. }
  6241. }
  6242. void Client::SendQuestJournalUpdate(Quest* quest, bool updated) {
  6243. PacketStruct* packet = player->GetQuestJournalPacket(quest, GetVersion(), GetNameCRC(), updated);
  6244. if (packet) {
  6245. QueuePacket(packet->serialize());
  6246. safe_delete(packet);
  6247. }
  6248. }
  6249. void Client::ReloadQuests() {
  6250. vector<int32> ids = player->GetQuestIDs();
  6251. Quest* quest = 0;
  6252. for (int32 i = 0; i < ids.size(); i++) {
  6253. quest = master_quest_list.GetQuest(ids[i]);
  6254. if (quest)
  6255. AddPlayerQuest(quest, false);
  6256. else
  6257. RemovePlayerQuest(ids[i]);
  6258. }
  6259. }
  6260. Quest* Client::GetPendingQuestAcceptance(int32 item_id) {
  6261. std::unique_lock lock(MPendingQuestAccept);
  6262. bool found_quest = false;
  6263. vector<int32>::iterator itr;
  6264. int32 questID = 0;
  6265. Quest* quest = nullptr;
  6266. for (itr = pending_quest_accept.begin(); itr != pending_quest_accept.end();) {
  6267. questID = *itr;
  6268. bool quest_exists = false;
  6269. quest = GetPlayer()->PendingQuestAcceptance(questID, item_id, &quest_exists);
  6270. if(!quest_exists) {
  6271. LogWrite(CCLIENT__ERROR, 0, "Client", "Quest ID %u missing for Player %s, removing quest id from pending_quest_accept.", questID, GetPlayer()->GetName());
  6272. itr = pending_quest_accept.erase(itr);
  6273. quest = nullptr;
  6274. continue;
  6275. }
  6276. else if (quest) {
  6277. pending_quest_accept.erase(itr);
  6278. break;
  6279. }
  6280. itr++;
  6281. }
  6282. return quest;
  6283. }
  6284. void Client::AcceptQuestReward(Quest* quest, int32 item_id) {
  6285. int8 num_slots_needed = 0;
  6286. int16 free_slots = player->item_list.GetNumberOfFreeSlots();
  6287. Item* master_item = 0;
  6288. if (item_id > 0) {
  6289. num_slots_needed++;
  6290. master_item = master_item_list.GetItem(item_id);
  6291. }
  6292. int32 totalItems = 0;
  6293. vector<Item*>* items = 0;
  6294. vector<Item*>* tmpItems = 0;
  6295. bool isTempState = quest->GetQuestTemporaryState();
  6296. if(isTempState)
  6297. {
  6298. tmpItems = quest->GetTmpRewardItems();
  6299. if (tmpItems && tmpItems->size() > 0)
  6300. {
  6301. num_slots_needed += tmpItems->size();
  6302. totalItems += tmpItems->size();
  6303. }
  6304. }
  6305. else
  6306. {
  6307. items = quest->GetRewardItems();
  6308. if (items && items->size() > 0)
  6309. {
  6310. num_slots_needed += items->size();
  6311. totalItems += items->size();
  6312. }
  6313. }
  6314. RemoveQueuedQuestReward();
  6315. GetPlayer()->SetActiveReward(false);
  6316. if (free_slots >= num_slots_needed || (player->item_list.HasFreeBagSlot() && master_item && master_item->IsBag() && master_item->bag_info->num_slots >= totalItems)) {
  6317. if (master_item)
  6318. AddItem(item_id);
  6319. if (tmpItems && tmpItems->size() > 0) {
  6320. for (int32 i = 0; i < tmpItems->size(); i++)
  6321. AddItem(new Item(tmpItems->at(i)));
  6322. }
  6323. if (items && items->size() > 0) {
  6324. for (int32 i = 0; i < items->size(); i++)
  6325. AddItem(new Item(items->at(i)));
  6326. }
  6327. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6328. if (outapp)
  6329. QueuePacket(outapp);
  6330. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  6331. map<int32, sint32>::iterator itr;
  6332. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  6333. int32 faction_id = itr->first;
  6334. sint32 amount = itr->second;
  6335. if (amount > 0)
  6336. player->GetFactions()->IncreaseFaction(faction_id, amount);
  6337. else
  6338. player->GetFactions()->DecreaseFaction(faction_id, (amount * -1));
  6339. }
  6340. if(quest->GetQuestTemporaryState())
  6341. {
  6342. int64 total_coins = quest->GetCoinTmpReward();
  6343. if (total_coins > 0)
  6344. AwardCoins(total_coins, std::string("for completing ").append(quest->GetName()));
  6345. player->GetInfoStruct()->add_status_points(quest->GetStatusTmpReward());
  6346. }
  6347. else {
  6348. player->GetInfoStruct()->add_status_points(quest->GetStatusPoints());
  6349. }
  6350. quest->SetQuestTemporaryState(false);
  6351. player->SetCharSheetChanged(true);
  6352. }
  6353. else {
  6354. GetPlayer()->SetActiveReward(true);
  6355. AddPendingQuestAcceptReward(quest);
  6356. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots! Free some slots and try again.");
  6357. DisplayQuestComplete(quest, quest->GetQuestTemporaryState(), quest->GetQuestTemporaryDescription());
  6358. }
  6359. }
  6360. 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) {
  6361. 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))) {
  6362. /*if (quest)
  6363. text = quest->GetName();
  6364. else*/
  6365. return;//nothing to give
  6366. }
  6367. GetPlayer()->ClearPendingSelectableItemRewards(0, true);
  6368. GetPlayer()->ClearPendingItemRewards();
  6369. PacketStruct* packet2 = configReader.getStruct("WS_QuestRewardPackMsg", GetVersion());
  6370. if (packet2) {
  6371. int32 source_id = 0;
  6372. if (quest)
  6373. source_id = quest->GetQuestID();
  6374. int64 rewarded_coin = 0;
  6375. if (quest) {
  6376. if (quest->GetCoinsReward() > 0) {
  6377. if (quest->GetCoinsRewardMax() > 0)
  6378. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  6379. else
  6380. rewarded_coin = quest->GetCoinsReward();
  6381. }
  6382. quest->SetGeneratedCoin(rewarded_coin);
  6383. }
  6384. if (rewarded_coin > coin)
  6385. coin = rewarded_coin;
  6386. 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
  6387. if (coin > 0) {
  6388. player->AddCoins(coin);
  6389. PlaySound("coin_cha_ching");
  6390. }
  6391. }
  6392. packet2->setSubstructDataByName("reward_data", "unknown1", 255);
  6393. packet2->setSubstructDataByName("reward_data", "reward", header);
  6394. packet2->setSubstructDataByName("reward_data", "max_coin", coin);
  6395. if (player->GetGuild() && !was_displayed) {
  6396. 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
  6397. player->GetInfoStruct()->add_status_points(status_points);
  6398. player->SetCharSheetChanged(true);
  6399. }
  6400. packet2->setSubstructDataByName("reward_data", "status_points", status_points);
  6401. }
  6402. if(text)
  6403. packet2->setSubstructDataByName("reward_data", "text", text);
  6404. std::vector<Item*> items;
  6405. quest->GetTmpRewardItemsByID(&items);
  6406. if(rewards || items.size() > 0){
  6407. int32 item_count = items.size();
  6408. item_count += rewards ? rewards->size() : 0;
  6409. packet2->setSubstructArrayLengthByName("reward_data", "num_rewards", item_count);
  6410. int i = 0;
  6411. if(rewards) {
  6412. for (i = 0; i < rewards->size(); i++) {
  6413. Item* item = rewards->at(i);
  6414. if (item) {
  6415. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  6416. packet2->setItemArrayDataByName("item", item, player, i, 0, GetClientItemPacketOffset());
  6417. }
  6418. 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
  6419. player->AddPendingItemReward(item); //item reference will be deleted after the player accepts it
  6420. }
  6421. }
  6422. for (int j = 0; j < items.size(); j++) {
  6423. Item* item = items.at(j);
  6424. if (item) {
  6425. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  6426. packet2->setItemArrayDataByName("item", item, player, i, 0, GetClientItemPacketOffset());
  6427. }
  6428. 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
  6429. player->AddPendingItemReward(item); //item reference will be deleted after the player accepts it
  6430. i++;
  6431. }
  6432. }
  6433. if (selectable_rewards) {
  6434. packet2->setSubstructArrayLengthByName("reward_data", "num_select_rewards", selectable_rewards->size());
  6435. for (int i = 0; i < selectable_rewards->size(); i++) {
  6436. Item* item = selectable_rewards->at(i);
  6437. if (item) {
  6438. packet2->setArrayDataByName("select_reward_id", item->details.item_id, i);
  6439. packet2->setItemArrayDataByName("select_item", item, player, i, 0, GetClientItemPacketOffset());
  6440. 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
  6441. player->AddPendingSelectableItemReward(source_id, item); //item reference will be deleted after the player selects one
  6442. }
  6443. }
  6444. }
  6445. if (factions) {
  6446. map<int32, sint32>::iterator itr;
  6447. map<Faction*, signed int> factions_map;
  6448. for (itr = factions->begin(); itr != factions->end(); itr++) {
  6449. Faction* faction = master_faction_list.GetFaction(itr->first);
  6450. if (faction)
  6451. factions_map[faction] = itr->second;
  6452. }
  6453. packet2->setSubstructArrayLengthByName("reward_data", "num_factions", factions_map.size());
  6454. map<Faction*, signed int>::iterator faction_itr;
  6455. int8 i = 0;
  6456. for (faction_itr = factions_map.begin(); faction_itr != factions_map.end(); faction_itr++) {
  6457. packet2->setArrayDataByName("faction_name", faction_itr->first->name.c_str(), i);
  6458. sint32 amount = faction_itr->second;
  6459. packet2->setArrayDataByName("amount", amount, i);
  6460. if (!quest) { //this entire function is for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  6461. if (amount > 0)
  6462. player->GetFactions()->IncreaseFaction(faction_itr->first->id, amount);
  6463. else
  6464. player->GetFactions()->DecreaseFaction(faction_itr->first->id, (amount * -1));
  6465. }
  6466. i++;
  6467. }
  6468. }
  6469. QueuePacket(packet2->serialize());
  6470. safe_delete(packet2);
  6471. }
  6472. }
  6473. void Client::PopulateQuestRewardItems(vector <Item*>* items, PacketStruct* packet,
  6474. std::string num_rewards_str, std::string reward_id_str, std::string item_str) {
  6475. if(!items || !packet)
  6476. return;
  6477. if (items) {
  6478. int32 total_item_count = 0;
  6479. for(int s=0;s<items->size();s++) {
  6480. Item* tmpItem = items->at(s);
  6481. if(tmpItem) {
  6482. if(tmpItem->details.count > 1) {
  6483. total_item_count += tmpItem->details.count;
  6484. }
  6485. else {
  6486. total_item_count += 1;
  6487. }
  6488. }
  6489. }
  6490. packet->setArrayLengthByName(num_rewards_str.c_str(), total_item_count);
  6491. int16 count = 0;
  6492. int16 pos = 0;
  6493. for (int32 i = 0; i < items->size();) {
  6494. packet->setArrayDataByName(reward_id_str.c_str(), items->at(i)->details.item_id, pos);
  6495. if (version < 860)
  6496. packet->setItemArrayDataByName(item_str.c_str(), items->at(i), player, pos, 0, GetClientItemPacketOffset());
  6497. else if (version < 1193)
  6498. packet->setItemArrayDataByName(item_str.c_str(), items->at(i), player, pos);
  6499. else
  6500. packet->setItemArrayDataByName(item_str.c_str(), items->at(i), player, pos, 0, 2);
  6501. pos++;
  6502. if(count >= items->at(i)->details.count-1) {
  6503. count = 0;
  6504. }
  6505. else if(items->at(i)->details.count > 1) {
  6506. count++;
  6507. continue;
  6508. }
  6509. i++;
  6510. }
  6511. }
  6512. }
  6513. void Client::DisplayQuestComplete(Quest* quest, bool tempReward, std::string customDescription, bool was_displayed) {
  6514. if (!quest)
  6515. return;
  6516. if (GetVersion() <= 561) {
  6517. DisplayQuestRewards(quest, 0, quest->GetRewardItems(), quest->GetSelectableRewardItems(), quest->GetRewardFactions(), "Quest Complete!", quest->GetStatusPoints(), tempReward ? customDescription.c_str() : quest->GetCompletedDescription(), was_displayed);
  6518. return;
  6519. }
  6520. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", GetVersion());
  6521. if (packet) {
  6522. packet->setDataByName("title", "Quest Reward!");
  6523. packet->setDataByName("name", quest->GetName());
  6524. if(tempReward)
  6525. {
  6526. packet->setDataByName("description", customDescription.c_str());
  6527. }
  6528. else
  6529. packet->setDataByName("description", quest->GetCompletedDescription());
  6530. packet->setDataByName("level", quest->GetLevel());
  6531. packet->setDataByName("encounter_level", quest->GetEncounterLevel());
  6532. int8 difficulty = 0;
  6533. if ((string)quest->GetType() == "Tradeskill")
  6534. difficulty = player->GetTSArrowColor(quest->GetLevel());
  6535. else
  6536. difficulty = player->GetArrowColor(quest->GetLevel());
  6537. packet->setDataByName("difficulty", difficulty);
  6538. if(tempReward)
  6539. {
  6540. packet->setDataByName("max_coin", quest->GetCoinTmpReward());
  6541. packet->setDataByName("min_coin", quest->GetCoinTmpReward());
  6542. packet->setDataByName("status_points", quest->GetStatusPoints());
  6543. }
  6544. else
  6545. {
  6546. int64 rewarded_coin = 0;
  6547. if (quest->GetCoinsReward() > 0) {
  6548. if (quest->GetCoinsRewardMax() > 0)
  6549. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  6550. else
  6551. rewarded_coin = quest->GetCoinsReward();
  6552. }
  6553. quest->SetGeneratedCoin(rewarded_coin);
  6554. packet->setDataByName("max_coin", rewarded_coin);
  6555. packet->setDataByName("min_coin", rewarded_coin);
  6556. packet->setDataByName("status_points", quest->GetStatusPoints());
  6557. }
  6558. if(tempReward) {
  6559. PopulateQuestRewardItems(quest->GetTmpRewardItems(), packet);
  6560. }
  6561. else
  6562. {
  6563. vector<Item*>* items2 = quest->GetSelectableRewardItems();
  6564. PopulateQuestRewardItems(quest->GetRewardItems(), packet);
  6565. PopulateQuestRewardItems(quest->GetSelectableRewardItems(), packet, std::string("num_select_rewards"),
  6566. std::string("select_reward_id"), std::string("select_item"));
  6567. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  6568. if (reward_factions && reward_factions->size() > 0) {
  6569. packet->setArrayLengthByName("num_factions", reward_factions->size());
  6570. map<int32, sint32>::iterator itr;
  6571. int16 index = 0;
  6572. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  6573. int32 faction_id = itr->first;
  6574. sint32 amount = itr->second;
  6575. const char* faction_name = master_faction_list.GetFactionNameByID(faction_id);
  6576. if (faction_name) {
  6577. packet->setArrayDataByName("faction_name", const_cast<char*>(faction_name), index);
  6578. packet->setArrayDataByName("amount", amount, index);
  6579. }
  6580. index++;
  6581. }
  6582. }
  6583. }
  6584. EQ2Packet* outapp = packet->serialize();
  6585. // DumpPacket(outapp);
  6586. QueuePacket(outapp);
  6587. safe_delete(packet);
  6588. }
  6589. }
  6590. void Client::DisplayRandomizeFeatures(int32 flags) {
  6591. SimpleMessage(CHANNEL_NARRATIVE, "Showing Active Randomize Features:");
  6592. if (flags > 0) {
  6593. if (flags & RANDOMIZE_GENDER)
  6594. SimpleMessage(CHANNEL_NARRATIVE, "- Gender");
  6595. if (flags & RANDOMIZE_RACE)
  6596. SimpleMessage(CHANNEL_NARRATIVE, "- Race");
  6597. if (flags & RANDOMIZE_MODEL_TYPE)
  6598. SimpleMessage(CHANNEL_NARRATIVE, "- Model");
  6599. if (flags & RANDOMIZE_FACIAL_HAIR_TYPE)
  6600. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair");
  6601. if (flags & RANDOMIZE_HAIR_TYPE)
  6602. SimpleMessage(CHANNEL_NARRATIVE, "- Hair");
  6603. if (flags & RANDOMIZE_WING_TYPE)
  6604. SimpleMessage(CHANNEL_NARRATIVE, "- Wing");
  6605. if (flags & RANDOMIZE_CHEEK_TYPE)
  6606. SimpleMessage(CHANNEL_NARRATIVE, "- Cheek");
  6607. if (flags & RANDOMIZE_CHIN_TYPE)
  6608. SimpleMessage(CHANNEL_NARRATIVE, "- Chin");
  6609. if (flags & RANDOMIZE_EAR_TYPE)
  6610. SimpleMessage(CHANNEL_NARRATIVE, "- Ear");
  6611. if (flags & RANDOMIZE_EYE_BROW_TYPE)
  6612. SimpleMessage(CHANNEL_NARRATIVE, "- Eyebrow");
  6613. if (flags & RANDOMIZE_EYE_TYPE)
  6614. SimpleMessage(CHANNEL_NARRATIVE, "- Eye");
  6615. if (flags & RANDOMIZE_LIP_TYPE)
  6616. SimpleMessage(CHANNEL_NARRATIVE, "- Lip");
  6617. if (flags & RANDOMIZE_NOSE_TYPE)
  6618. SimpleMessage(CHANNEL_NARRATIVE, "- Nose");
  6619. if (flags & RANDOMIZE_EYE_COLOR)
  6620. SimpleMessage(CHANNEL_NARRATIVE, "- Eye Color");
  6621. if (flags & RANDOMIZE_HAIR_COLOR1)
  6622. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color1");
  6623. if (flags & RANDOMIZE_HAIR_COLOR2)
  6624. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color2");
  6625. if (flags & RANDOMIZE_HAIR_HIGHLIGHT)
  6626. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color Highlights");
  6627. if (flags & RANDOMIZE_HAIR_FACE_COLOR)
  6628. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color");
  6629. if (flags & RANDOMIZE_HAIR_FACE_HIGHLIGHT_COLOR)
  6630. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color Highlights");
  6631. if (flags & RANDOMIZE_HAIR_TYPE_COLOR)
  6632. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Color");
  6633. if (flags & RANDOMIZE_HAIR_TYPE_HIGHLIGHT_COLOR)
  6634. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Highlights");
  6635. if (flags & RANDOMIZE_SKIN_COLOR)
  6636. SimpleMessage(CHANNEL_NARRATIVE, "- Skin Color");
  6637. if (flags & RANDOMIZE_WING_COLOR1)
  6638. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color1");
  6639. if (flags & RANDOMIZE_WING_COLOR2)
  6640. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color2");
  6641. }
  6642. else
  6643. {
  6644. SimpleMessage(CHANNEL_NARRATIVE, "- No Randomization Set.");
  6645. }
  6646. }
  6647. void Client::GiveQuestReward(Quest* quest, bool has_displayed) {
  6648. current_quest_id = 0;
  6649. if(!quest->GetQuestTemporaryState() && !has_displayed)
  6650. {
  6651. quest->IncrementCompleteCount();
  6652. player->AddCompletedQuest(quest);
  6653. }
  6654. AddPendingQuestAcceptReward(quest);
  6655. DisplayQuestComplete(quest, quest->GetQuestTemporaryState(), quest->GetQuestTemporaryDescription());
  6656. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6657. SendQuestJournal();
  6658. if(quest->GetQuestTemporaryState()) {
  6659. return;
  6660. }
  6661. if(!has_displayed) {
  6662. if (quest->GetExpReward() > 0) {
  6663. int32 xp = quest->GetExpReward();
  6664. player->AddXP(xp);
  6665. }
  6666. if (quest->GetTSExpReward() > 0) {
  6667. int8 ts_level = player->GetTSLevel();
  6668. int32 xp = quest->GetTSExpReward();
  6669. if (player->AddTSXP(xp)) {
  6670. Message(CHANNEL_REWARD, "You gain %u tradeskill experience!", (int32)xp);
  6671. if (player->GetTSLevel() != ts_level)
  6672. ChangeTSLevel(ts_level, player->GetTSLevel());
  6673. player->SetCharSheetChanged(true);
  6674. }
  6675. }
  6676. int64 total_coins = quest->GetGeneratedCoin();
  6677. if (total_coins > 0)
  6678. AwardCoins(total_coins, std::string("for completing ").append(quest->GetName()));
  6679. player->RemoveQuest(quest->GetQuestID(), false);
  6680. }
  6681. if (quest->GetQuestGiver() > 0)
  6682. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  6683. if(!has_displayed) {
  6684. RemovePlayerQuest(quest->GetQuestID(), true, false);
  6685. }
  6686. }
  6687. 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) {
  6688. std::unique_lock lock(MConversation);
  6689. PacketStruct* packet = configReader.getStruct("WS_DialogOpen", GetVersion());
  6690. if (packet) {
  6691. packet->setDataByName("conversation_id", conversation_id);
  6692. packet->setDataByName("text", text);
  6693. packet->setDataByName("language", language); // default 0
  6694. packet->setDataByName("enable_blue_ui", 0); // default 0
  6695. packet->setDataByName("can_close", can_close); // default 1
  6696. conversation_map[conversation_id].clear();
  6697. if (conversations) {
  6698. packet->setArrayLengthByName("num_responses", conversations->size());
  6699. for (int32 i = 0; i < conversations->size(); i++) {
  6700. packet->setArrayDataByName("response", conversations->at(i).option.c_str(), i);
  6701. if (conversations->at(i).function.length() > 0)
  6702. conversation_map[conversation_id][i] = conversations->at(i).function;
  6703. }
  6704. }
  6705. packet->setDataByName("spawn_id", spawn_id);
  6706. if (mp3) {
  6707. packet->setDataByName("voice", mp3);
  6708. packet->setDataByName("key1", key1);
  6709. packet->setDataByName("key2", key2);
  6710. }
  6711. QueuePacket(packet->serialize());
  6712. safe_delete(packet);
  6713. }
  6714. }
  6715. 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) {
  6716. if (!item || !text || !conversations || conversations->size() == 0) {
  6717. return;
  6718. }
  6719. int32 conversation_id = GetConversationID(0, item);
  6720. if (conversation_id == 0) {
  6721. next_conversation_id++;
  6722. conversation_id = next_conversation_id;
  6723. }
  6724. MConversation.lock();
  6725. conversation_items[conversation_id] = item;
  6726. MConversation.unlock();
  6727. if (type == 4)
  6728. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2, language, can_close);
  6729. else
  6730. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2, language, can_close);
  6731. }
  6732. 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) {
  6733. if (!src || !(type == 1 || type == 2 || type == 3) || !text /*|| !conversations || conversations->size() == 0*/) {
  6734. return;
  6735. }
  6736. int32 conversation_id = GetConversationID(src, 0);
  6737. if (conversation_id == 0) {
  6738. next_conversation_id++;
  6739. conversation_id = next_conversation_id;
  6740. }
  6741. MConversation.lock();
  6742. conversation_spawns[conversation_id] = src->GetID();
  6743. MConversation.unlock();
  6744. /* Spawns can start two different types of conversations.
  6745. * Type 1: The chat type with bubbles.
  6746. * Type 2: The dialog type with the blue box. */
  6747. if (type == 1)
  6748. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(src), conversations, text, mp3, key1, key2, language, can_close);
  6749. else if (type == 2)
  6750. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2, language, can_close);
  6751. else //if (type == 3)
  6752. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2, language, can_close);
  6753. }
  6754. void Client::CloseDialog(int32 conversation_id) {
  6755. std::unique_lock lock(MConversation);
  6756. PacketStruct* packet = configReader.getStruct("WS_ServerDialogClose", GetVersion());
  6757. if (packet) {
  6758. packet->setDataByName("conversation_id", conversation_id);
  6759. QueuePacket(packet->serialize());
  6760. safe_delete(packet);
  6761. }
  6762. std::map<int32, Item*>::iterator itr;
  6763. while((itr = conversation_items.find(conversation_id)) != conversation_items.end())
  6764. {
  6765. conversation_items.erase(itr);
  6766. }
  6767. std::map<int32, int32>::iterator itr2 = conversation_spawns.find(conversation_id);
  6768. while((itr2 = conversation_spawns.find(conversation_id)) != conversation_spawns.end())
  6769. {
  6770. conversation_spawns.erase(itr2);
  6771. }
  6772. }
  6773. int32 Client::GetConversationID(Spawn* spawn, Item* item) {
  6774. std::shared_lock lock(MConversation);
  6775. int32 conversation_id = 0;
  6776. if (spawn) {
  6777. map<int32, int32>::iterator itr;
  6778. for (itr = conversation_spawns.begin(); itr != conversation_spawns.end(); itr++) {
  6779. if (itr->second == spawn->GetID()) {
  6780. conversation_id = itr->first;
  6781. break;
  6782. }
  6783. }
  6784. }
  6785. else if (item) {
  6786. map<int32, Item*>::iterator itr;
  6787. for (itr = conversation_items.begin(); itr != conversation_items.end(); itr++) {
  6788. if (itr->second == item) {
  6789. conversation_id = itr->first;
  6790. break;
  6791. }
  6792. }
  6793. }
  6794. return conversation_id;
  6795. }
  6796. Spawn* Client::GetCombineSpawn() {
  6797. return combine_spawn;
  6798. }
  6799. bool Client::ShouldTarget() {
  6800. return should_target;
  6801. }
  6802. void Client::TargetSpawn(Spawn* spawn) {
  6803. should_target = false;
  6804. PacketStruct* packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  6805. if (packet) {
  6806. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  6807. QueuePacket(packet->serialize());
  6808. safe_delete(packet);
  6809. }
  6810. }
  6811. void Client::CombineSpawns(float radius, Spawn* spawn) {
  6812. combine_spawn = spawn;
  6813. spawn->RemoveSpawnFromGroup(true);
  6814. if (!GetCurrentZone()->AddCloseSpawnsToSpawnGroup(combine_spawn, radius))
  6815. SimpleMessage(CHANNEL_COLOR_YELLOW, "One or more spawns are in a spawn group and cannot be combined until they are removed from their group.");
  6816. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  6817. should_target = true;
  6818. }
  6819. void Client::AddCombineSpawn(Spawn* spawn) {
  6820. if (combine_spawn && combine_spawn != spawn && spawn) {
  6821. combine_spawn->AddSpawnToGroup(spawn);
  6822. spawn->AddSpawnToGroup(combine_spawn);
  6823. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  6824. }
  6825. else if (spawn)
  6826. combine_spawn = spawn;
  6827. should_target = true;
  6828. }
  6829. void Client::RemoveCombineSpawn(Spawn* spawn) {
  6830. if (combine_spawn && spawn)
  6831. spawn->RemoveSpawnFromGroup();
  6832. if (combine_spawn == spawn)
  6833. combine_spawn->RemoveSpawnFromGroup(true);
  6834. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  6835. if (combine_spawn == spawn)
  6836. combine_spawn = 0;
  6837. }
  6838. void Client::SaveCombineSpawns(const char* name) {
  6839. if (!combine_spawn) {
  6840. return;
  6841. }
  6842. vector<Spawn*>* spawns = combine_spawn->GetSpawnGroup();
  6843. if (!spawns) {
  6844. return;
  6845. }
  6846. int32 count = spawns->size();
  6847. int32 spawnLocationID = 0;
  6848. if (count == 1)
  6849. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error: You only have a single Spawn in the group!");
  6850. else if ((spawnLocationID = database.SaveCombinedSpawnLocation(GetCurrentZone(), combine_spawn, name)) > 0) {
  6851. Message(CHANNEL_COLOR_YELLOW, "Successfully combined %u spawns into spawn location: %u", count, spawnLocationID);
  6852. // we remove the spawn inside SaveCombinedSpawnLocation
  6853. //GetCurrentZone()->RemoveSpawn(combine_spawn);
  6854. }
  6855. else
  6856. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn group, check console for details.");
  6857. safe_delete(spawns);
  6858. combine_spawn = 0;
  6859. }
  6860. bool Client::AddItem(int32 item_id, int16 quantity, AddItemType type) {
  6861. Item* master_item = master_item_list.GetItem(item_id);
  6862. Item* item = 0;
  6863. if (master_item)
  6864. item = new Item(master_item);
  6865. if (item) {
  6866. if (quantity > 0)
  6867. item->details.count = quantity;
  6868. return AddItem(item, nullptr, type);
  6869. }
  6870. else
  6871. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  6872. return false;
  6873. }
  6874. bool Client::AddItem(Item* item, bool* item_deleted, AddItemType type) {
  6875. if (!item) {
  6876. return false;
  6877. }
  6878. if (player->AddItem(item, type)) {
  6879. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6880. if (outapp) {
  6881. //DumpPacket(outapp);
  6882. QueuePacket(outapp);
  6883. //resend bag desc with new item name added
  6884. outapp = player->SendBagUpdate(item->details.unique_id, GetVersion());
  6885. if (outapp) {
  6886. //DumpPacket(outapp);
  6887. QueuePacket(outapp);
  6888. }
  6889. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  6890. DumpPacket(app);
  6891. client->QueuePacket(app);
  6892. */
  6893. }
  6894. CheckPlayerQuestsItemUpdate(item);
  6895. if (item->GetItemScript() && lua_interface)
  6896. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  6897. }
  6898. else {
  6899. lua_interface->SetLuaUserDataStale(item);
  6900. // likely lore conflict
  6901. if(item_deleted)
  6902. *item_deleted = true;
  6903. return false;
  6904. }
  6905. return true;
  6906. }
  6907. bool Client::AddItemToBank(int32 item_id, int16 quantity) {
  6908. Item* master_item = master_item_list.GetItem(item_id);
  6909. Item* item = 0;
  6910. if (master_item)
  6911. item = new Item(master_item);
  6912. if (item) {
  6913. if (quantity > 0)
  6914. item->details.count = quantity;
  6915. return AddItemToBank(item);
  6916. }
  6917. else
  6918. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  6919. return false;
  6920. }
  6921. bool Client::AddItemToBank(Item* item) {
  6922. if (!item) {
  6923. return false;
  6924. }
  6925. if (player->AddItemToBank(item)) {
  6926. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6927. if (outapp) {
  6928. QueuePacket(outapp);
  6929. //resend bag desc with new item name added
  6930. outapp = player->SendBagUpdate(item->details.inv_slot_id, GetVersion());
  6931. if (outapp)
  6932. QueuePacket(outapp);
  6933. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  6934. DumpPacket(app);
  6935. client->QueuePacket(app);
  6936. */
  6937. }
  6938. CheckPlayerQuestsItemUpdate(item);
  6939. if (item->GetItemScript() && lua_interface)
  6940. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  6941. }
  6942. else {
  6943. lua_interface->SetLuaUserDataStale(item);
  6944. // likely lore conflict
  6945. safe_delete(item);
  6946. return false;
  6947. }
  6948. return true;
  6949. }
  6950. void Client::UnequipItem(int16 index, sint32 bag_id, int8 to_slot, int8 appearance_equip) {
  6951. vector<EQ2Packet*> packets = GetPlayer()->UnequipItem(index, bag_id, to_slot, GetVersion(), appearance_equip);
  6952. EQ2Packet* outapp = 0;
  6953. for(int32 i=0;i<packets.size();i++)
  6954. {
  6955. outapp = packets[i];
  6956. if(outapp)
  6957. QueuePacket(outapp);
  6958. }
  6959. GetPlayer()->UpdateWeapons();
  6960. EQ2Packet* characterSheetPackets = GetPlayer()->GetPlayerInfo()->serialize(GetVersion());
  6961. QueuePacket(characterSheetPackets);
  6962. }
  6963. bool Client::RemoveItem(Item* item, int16 quantity, bool force_override_no_delete) {
  6964. EQ2Packet* outapp;
  6965. bool delete_item = false;
  6966. assert(item);
  6967. if (quantity > 0 && !item->IsBag() && item->details.count > quantity) {
  6968. item->details.count -= quantity;
  6969. item->save_needed = true;
  6970. }
  6971. else {
  6972. database.DeleteItem(character_id, item, 0);
  6973. player->GetPlayerItemList()->RemoveItem(item, false);
  6974. delete_item = true;
  6975. }
  6976. if(force_override_no_delete)
  6977. delete_item = false;
  6978. if ((outapp = player->SendInventoryUpdate(version))) {
  6979. QueuePacket(outapp);
  6980. if (item->GetItemScript() && lua_interface)
  6981. lua_interface->RunItemScript(item->GetItemScript(), "removed", item, player);
  6982. if (delete_item)
  6983. {
  6984. PurgeItem(item);
  6985. lua_interface->SetLuaUserDataStale(item);
  6986. safe_delete(item);
  6987. }
  6988. GetPlayer()->CalculateApplyWeight();
  6989. return true;
  6990. }
  6991. return false;
  6992. }
  6993. void Client::SetLuaDebugClient(bool val) {
  6994. if (val)
  6995. lua_debug_timer.Start();
  6996. lua_debug = val;
  6997. if (lua_interface && !val) {
  6998. lua_interface->RemoveDebugClients(this);
  6999. lua_debug_timer.Disable();
  7000. }
  7001. }
  7002. void Client::SetMerchantTransaction(Spawn* spawn) {
  7003. merchant_transaction = spawn;
  7004. }
  7005. Spawn* Client::GetMerchantTransaction() {
  7006. return merchant_transaction;
  7007. }
  7008. void Client::SetMailTransaction(Spawn* spawn) {
  7009. ResetSendMail(spawn ? false : true);
  7010. MMailWindowMutex.lock();
  7011. mail_transaction = spawn;
  7012. MMailWindowMutex.unlock();
  7013. }
  7014. Spawn* Client::GetMailTransaction() {
  7015. return mail_transaction;
  7016. }
  7017. void Client::PlaySound(const char* name) {
  7018. if (name) {
  7019. PacketStruct* packet = configReader.getStruct("WS_PlaySound", GetVersion());
  7020. if (packet) {
  7021. packet->setMediumStringByName("name", name);
  7022. QueuePacket(packet->serialize());
  7023. safe_delete(packet);
  7024. }
  7025. }
  7026. }
  7027. float Client::CalculateBuyMultiplier(int32 merchant_id) {
  7028. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  7029. if(multiplier){
  7030. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  7031. float diff_low = faction_val - multiplier->faction_min;
  7032. if(diff_low < 0)
  7033. diff_low*=-1;
  7034. float total_diff = multiplier->faction_max - multiplier->faction_min;
  7035. if(total_diff < 0)
  7036. total_diff*=-1;
  7037. float buy_multiplier = multiplier->high_buy_multiplier - multiplier->low_buy_multiplier;
  7038. float total1 = (diff_low/total_diff);
  7039. float final_buy_multiplier = total1*buy_multiplier + total1*multiplier->low_buy_multiplier;
  7040. return final_buy_multiplier;
  7041. }*/
  7042. return 1;
  7043. }
  7044. float Client::CalculateSellMultiplier(int32 merchant_id) {
  7045. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  7046. if(multiplier){
  7047. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  7048. float diff_low = faction_val - multiplier->faction_min;
  7049. if(diff_low < 0)
  7050. diff_low*=-1;
  7051. float total_diff = multiplier->faction_max - multiplier->faction_min;
  7052. if(total_diff < 0)
  7053. total_diff*=-1;
  7054. float sell_multiplier = multiplier->high_sell_multiplier - multiplier->low_sell_multiplier;
  7055. float total1 = (diff_low/total_diff);
  7056. float final_sell_multiplier = total1*sell_multiplier + total1*multiplier->low_sell_multiplier;
  7057. return final_sell_multiplier;
  7058. }*/
  7059. return 1;
  7060. }
  7061. void Client::SellItem(int32 item_id, int16 quantity, int32 unique_id) {
  7062. Spawn* spawn = GetMerchantTransaction();
  7063. Guild* guild = GetPlayer()->GetGuild();
  7064. if (spawn && spawn->GetMerchantID() > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY)) &&
  7065. spawn->IsClientInMerchantLevelRange(this)) {
  7066. int32 total_sell_price = 0;
  7067. int32 total_status_sell_price = 0; //for status
  7068. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  7069. int32 sell_price = 0;
  7070. int32 status_sell_price = 0; //for status
  7071. Item* master_item = master_item_list.GetItem(item_id);
  7072. Item* item = 0;
  7073. if (unique_id == 0)
  7074. item = player->item_list.GetItemFromID(item_id, quantity);
  7075. else
  7076. item = player->item_list.GetItemFromUniqueID(unique_id);
  7077. if (!item)
  7078. item = player->item_list.GetItemFromID(item_id);
  7079. if (item && master_item) {
  7080. if(item->details.item_locked)
  7081. {
  7082. SimpleMessage(CHANNEL_COLOR_RED, "You cannot sell the item in use.");
  7083. return;
  7084. }
  7085. else if(item->CheckFlag(NO_VALUE))
  7086. {
  7087. SimpleMessage(CHANNEL_COLOR_RED, "This item has no value.");
  7088. return;
  7089. }
  7090. else if (item->IsBag())
  7091. {
  7092. int32 bagitemcount = player->GetPlayerItemList()->GetItemCountInBag(item);
  7093. if (bagitemcount > 0) {
  7094. SimpleMessage(CHANNEL_COLOR_RED, "You cannot sell a bag with items inside it.");
  7095. return;
  7096. }
  7097. }
  7098. int32 sell_price = (int32)(master_item->sell_price * multiplier);
  7099. if (sell_price > item->sell_price)
  7100. sell_price = item->sell_price;
  7101. if (quantity > item->details.count)
  7102. quantity = item->details.count;
  7103. total_sell_price = sell_price * quantity;
  7104. //------------------------------For Selling Status Items
  7105. status_sell_price = (int32)(master_item->sell_status * multiplier);
  7106. if (status_sell_price > item->sell_status)
  7107. status_sell_price = item->sell_status;
  7108. if (quantity > item->details.count)
  7109. quantity = item->details.count;
  7110. total_status_sell_price = status_sell_price * quantity;
  7111. if(total_status_sell_price > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))
  7112. total_status_sell_price = 0;
  7113. player->GetInfoStruct()->add_status_points(total_status_sell_price);
  7114. int32 guildMaxLevel = 5 + item->details.recommended_level; // client hard codes +5 to the level
  7115. if (player->GetGuild() && guild->GetLevel() < guildMaxLevel) {
  7116. guild->UpdateGuildStatus(GetPlayer(), total_status_sell_price / 10);
  7117. guild->SendGuildMemberList();
  7118. guild->AddEXPCurrent((total_status_sell_price / 10), true);
  7119. }
  7120. if (quantity > 1)
  7121. {
  7122. if(total_status_sell_price)
  7123. 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);
  7124. else
  7125. 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());
  7126. }
  7127. else
  7128. {
  7129. if(total_status_sell_price)
  7130. 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);
  7131. else
  7132. 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());
  7133. }
  7134. player->AddCoins(total_sell_price);
  7135. if(!item->no_buy_back && (total_status_sell_price == 0 || (total_status_sell_price > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))))
  7136. AddBuyBack(unique_id, item_id, quantity, sell_price);
  7137. if (quantity >= item->details.count) {
  7138. database.DeleteItem(GetCharacterID(), item, 0);
  7139. player->item_list.DestroyItem(item->details.index);
  7140. }
  7141. else {
  7142. item->details.count -= quantity;
  7143. item->save_needed = true;
  7144. }
  7145. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  7146. if (outapp)
  7147. QueuePacket(outapp);
  7148. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  7149. SendBuyBackList();
  7150. }
  7151. }
  7152. }
  7153. void Client::BuyBack(int32 item_id, int16 quantity) {
  7154. Spawn* spawn = GetMerchantTransaction();
  7155. if (spawn && spawn->GetMerchantID() > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK)) &&
  7156. spawn->IsClientInMerchantLevelRange(this)) {
  7157. deque<BuyBackItem*>::iterator itr;
  7158. BuyBackItem* buyback = 0;
  7159. BuyBackItem* closest = 0;
  7160. MBuyBack.readlock(__FUNCTION__, __LINE__);
  7161. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  7162. buyback = *itr;
  7163. if (buyback->unique_id == item_id) {
  7164. closest = buyback;
  7165. quantity = buyback->quantity;
  7166. break;
  7167. }
  7168. }
  7169. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  7170. if (closest) {
  7171. Item* item = 0;
  7172. Item* master_item = master_item_list.GetItem(closest->item_id);
  7173. if (master_item) {
  7174. item = new Item(master_item);
  7175. if (closest->quantity >= quantity)
  7176. item->details.count = quantity;
  7177. else
  7178. item->details.count = closest->quantity;
  7179. }
  7180. bool itemDeleted = false;
  7181. bool itemAdded = false;
  7182. sint64 dispFlags = 0;
  7183. if (item && item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "buyback_display_flags", item, player, nullptr, &dispFlags) && (dispFlags & DISPLAY_FLAG_NO_BUY))
  7184. SimpleMessage(CHANNEL_NARRATIVE, "You do not meet all the requirements to buy this item.");
  7185. else if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item))
  7186. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  7187. else if (player->RemoveCoins(closest->quantity * closest->price)) {
  7188. bool removed = false;
  7189. if (closest->quantity == quantity) {
  7190. MBuyBack.writelock(__FUNCTION__, __LINE__);
  7191. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  7192. if (*itr == closest) {
  7193. buy_back_items.erase(itr);
  7194. removed = true;
  7195. break;
  7196. }
  7197. }
  7198. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  7199. }
  7200. else {
  7201. closest->quantity -= quantity;
  7202. closest->save_needed = true;
  7203. }
  7204. itemAdded = AddItem(item, &itemDeleted);
  7205. if (removed) {
  7206. database.DeleteBuyBack(GetCharacterID(), closest->item_id, closest->quantity, closest->price);
  7207. safe_delete(closest);
  7208. }
  7209. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  7210. SendBuyBackList();
  7211. }
  7212. else
  7213. SimpleMessage(CHANNEL_COLOR_RED, "You cannot afford this item.");
  7214. if(!itemAdded && !itemDeleted) {
  7215. lua_interface->SetLuaUserDataStale(item);
  7216. safe_delete(item);
  7217. }
  7218. }
  7219. }
  7220. }
  7221. void Client::BuyItem(int32 item_id, int16 quantity) {
  7222. // Get the merchant we are buying from
  7223. Spawn* spawn = GetMerchantTransaction();
  7224. // Make sure the spawn has a merchant list
  7225. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  7226. int32 total_buy_price = 0;
  7227. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  7228. int32 sell_price = 0;
  7229. Item* master_item = master_item_list.GetItem(item_id);
  7230. Item* item = 0;
  7231. int16 total_available = 0;
  7232. vector<MerchantItemInfo>* temp;
  7233. vector<MerchantItemInfo>::iterator itr;
  7234. MerchantItemInfo* ItemInfo = 0;
  7235. temp = world.GetMerchantList(spawn->GetMerchantID());
  7236. for (itr = temp->begin(); itr != temp->end(); itr++) {
  7237. if ((*itr).item_id == item_id) {
  7238. ItemInfo = &(*itr);
  7239. break;
  7240. }
  7241. }
  7242. if (master_item && ItemInfo) {
  7243. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO) {
  7244. quantity = 1;
  7245. total_available = 0xFFFF;
  7246. sell_price = master_item->sell_price;
  7247. }
  7248. else {
  7249. total_available = world.GetMerchantItemQuantity(spawn->GetMerchantID(), item_id);
  7250. sell_price = (int32)(master_item->sell_price * multiplier);
  7251. if (quantity > total_available)
  7252. quantity = total_available;
  7253. }
  7254. sint64 dispFlags = 0;
  7255. 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))
  7256. {
  7257. SimpleMessage(CHANNEL_NARRATIVE, "You do not meet all the requirements to buy this item.");
  7258. return;
  7259. }
  7260. if(quantity < 1)
  7261. {
  7262. SimpleMessage(CHANNEL_COLOR_RED, "Merchant does not have item for purchase (quantity < 1).");
  7263. return;
  7264. }
  7265. total_buy_price = sell_price * quantity;
  7266. item = new Item(master_item);
  7267. item->details.count = quantity;
  7268. if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item)) {
  7269. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  7270. lua_interface->SetLuaUserDataStale(item);
  7271. safe_delete(item);
  7272. }
  7273. else {
  7274. // Price not set in the merchant_inventory table, use the old method
  7275. if (ItemInfo->price_item_id == 0 && ItemInfo->price_item2_id == 0 && ItemInfo->price_status == 0 && ItemInfo->price_stationcash == 0 && ItemInfo->price_coins == 0) {
  7276. if (player->RemoveCoins(total_buy_price)) {
  7277. item->SetMaxSellValue(sell_price);
  7278. if (quantity > 1)
  7279. 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());
  7280. else
  7281. 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());
  7282. bool itemDeleted = false;
  7283. AddItem(item, &itemDeleted);
  7284. if(!itemDeleted) {
  7285. CheckPlayerQuestsItemUpdate(item);
  7286. if (item && total_available < 0xFF) {
  7287. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  7288. SendBuyMerchantList();
  7289. }
  7290. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  7291. PlayLotto(total_buy_price, item->details.item_id);
  7292. }
  7293. }
  7294. else {
  7295. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  7296. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  7297. PlaySound("buy_failed");
  7298. }
  7299. }
  7300. else {
  7301. // Price set in merchant_inventory table
  7302. // Check if the player has enough status, coins and staion cash to buy the item before checking the items
  7303. // TODO: need to add support for station cash
  7304. if (player->GetInfoStruct()->get_status_points() >= (ItemInfo->price_status * quantity) && player->HasCoins(ItemInfo->price_coins * quantity)) {
  7305. // Check items
  7306. int16 item_quantity = 0;
  7307. // Default these to true in case price_item_id or price_item2_id was never set
  7308. bool hasItem1 = true;
  7309. bool hasItem2 = true;
  7310. Item* tempItem1 = 0;
  7311. Item* tempItem2 = 0;
  7312. if (ItemInfo->price_item_id != 0) {
  7313. // Same item for whatever reason lets add the quantities together
  7314. if (ItemInfo->price_item_id == ItemInfo->price_item2_id)
  7315. item_quantity = ItemInfo->price_item_qty + ItemInfo->price_item2_qty;
  7316. else
  7317. item_quantity = ItemInfo->price_item_qty;
  7318. tempItem1 = player->item_list.GetItemFromID(ItemInfo->price_item_id);
  7319. if (tempItem1) {
  7320. if (tempItem1->details.count < item_quantity)
  7321. hasItem1 = false;
  7322. }
  7323. else {
  7324. hasItem1 = false;
  7325. }
  7326. }
  7327. // Check item2, if item_quantity is greater then item1 quantity then item2 is the same item
  7328. // as item1 and we already checked for it so we can skip this check
  7329. if (ItemInfo->price_item2_id != 0 && item_quantity <= ItemInfo->price_item_qty) {
  7330. tempItem2 = player->item_list.GetItemFromID(ItemInfo->price_item2_id);
  7331. if (tempItem2) {
  7332. if (tempItem2->details.count < ItemInfo->price_item2_qty)
  7333. hasItem2 = false;
  7334. }
  7335. else {
  7336. hasItem2 = false;
  7337. }
  7338. }
  7339. // if we have every thing then remove the price and give the item
  7340. if (hasItem1 && hasItem2) {
  7341. player->GetInfoStruct()->set_status_points(player->GetInfoStruct()->get_status_points() - (ItemInfo->price_status * quantity));
  7342. // TODO: station cash
  7343. // The update that would normally be sent after modifing the players inventory is automatically sent in AddItem wich is called later
  7344. // so there is no need to send it more then that one time
  7345. if (tempItem1) {
  7346. if (tempItem1->details.count > item_quantity) {
  7347. tempItem1->details.count -= item_quantity;
  7348. tempItem1->save_needed = true;
  7349. }
  7350. else {
  7351. database.DeleteItem(GetCharacterID(), tempItem1, 0);
  7352. player->item_list.DestroyItem(tempItem1->details.index);
  7353. }
  7354. }
  7355. if (tempItem2) {
  7356. if (tempItem2->details.count > ItemInfo->price_item2_qty) {
  7357. tempItem2->details.count -= ItemInfo->price_item2_qty;
  7358. tempItem2->save_needed = true;
  7359. }
  7360. else {
  7361. database.DeleteItem(GetCharacterID(), tempItem2, 0);
  7362. player->item_list.DestroyItem(tempItem2->details.index);
  7363. }
  7364. }
  7365. // 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
  7366. player->RemoveCoins(ItemInfo->price_coins * quantity);
  7367. item->SetMaxSellValue(sell_price);
  7368. if (quantity > 1)
  7369. 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());
  7370. else
  7371. 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());
  7372. bool itemDeleted = false;
  7373. AddItem(item, &itemDeleted);
  7374. if(!itemDeleted) {
  7375. CheckPlayerQuestsItemUpdate(item);
  7376. if (item && total_available < 0xFF) {
  7377. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  7378. SendBuyMerchantList();
  7379. }
  7380. SendSellMerchantList();
  7381. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  7382. PlayLotto(total_buy_price, item->details.item_id);
  7383. }
  7384. }
  7385. else {
  7386. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  7387. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  7388. PlaySound("buy_failed");
  7389. }
  7390. }
  7391. else {
  7392. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  7393. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  7394. PlaySound("buy_failed");
  7395. }
  7396. }
  7397. }
  7398. }
  7399. }
  7400. }
  7401. void Client::RepairItem(int32 item_id) {
  7402. Spawn* spawn = GetMerchantTransaction();
  7403. if (spawn) {
  7404. Item* item = player->item_list.GetItemFromID(item_id);
  7405. if (!item)
  7406. item = player->GetEquipmentList()->GetItemFromItemID(item_id);
  7407. if (item) {
  7408. if(item->CheckFlag2(NO_REPAIR)) {
  7409. Message(CHANNEL_MERCHANT, "The mender was unable to repair your items.");
  7410. PlaySound("buy_failed");
  7411. }
  7412. else {
  7413. int32 repair_cost = item->CalculateRepairCost();
  7414. if (player->RemoveCoins((int32)repair_cost)) {
  7415. item->generic_info.condition = 100;
  7416. item->save_needed = true;
  7417. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  7418. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  7419. QueuePacket(item->serialize(version, false, player));
  7420. Message(CHANNEL_MERCHANT, "You give %s %s to repair your %s.", spawn->GetName(), GetCoinMessage(repair_cost).c_str(), item->CreateItemLink(GetVersion()).c_str());
  7421. PlaySound("coin_cha_ching");
  7422. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  7423. SendRepairList();
  7424. }
  7425. else {
  7426. string popup_text = "You do not have enough coin to repair ";
  7427. string popup_item = item->CreateItemLink(GetVersion()).c_str();
  7428. popup_text.append(popup_item);
  7429. SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  7430. Message(CHANNEL_MERCHANT, "You do not have enough coin to repair %s.", item->CreateItemLink(GetVersion()).c_str());
  7431. PlaySound("buy_failed");
  7432. }
  7433. }
  7434. }
  7435. }
  7436. }
  7437. void Client::RepairAllItems() {
  7438. Spawn* spawn = GetMerchantTransaction();
  7439. if (spawn) {
  7440. vector<Item*>* repairable_items = GetRepairableItems();
  7441. if (repairable_items && repairable_items->size() > 0) {
  7442. vector<Item*>::iterator itr;
  7443. int64 total_cost = 0;
  7444. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++)
  7445. total_cost += (*itr)->CalculateRepairCost();
  7446. if (player->RemoveCoins((int32)total_cost)) {
  7447. Message(CHANNEL_MERCHANT, "You give %s to repair all of your items.", GetCoinMessage((int32)total_cost).c_str());
  7448. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++) {
  7449. Item* item = *itr;
  7450. if (item) {
  7451. item->generic_info.condition = 100;
  7452. item->save_needed = true;
  7453. QueuePacket(item->serialize(version, false, player));
  7454. Message(CHANNEL_COLOR_YELLOW, "Repaired: %s.", item->CreateItemLink(GetVersion()).c_str());
  7455. }
  7456. }
  7457. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  7458. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  7459. PlaySound("coin_cha_ching");
  7460. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  7461. SendRepairList();
  7462. }
  7463. else {
  7464. string popup_text = "You do not have enough coin to repair all of your items. ";
  7465. SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  7466. SimpleMessage(CHANNEL_MERCHANT, "You do not have enough coin to repair all of your items.");
  7467. PlaySound("buy_failed");
  7468. }
  7469. }
  7470. safe_delete(repairable_items);
  7471. }
  7472. }
  7473. void Client::SendAchievementsList()
  7474. {
  7475. /*map<int32, Achievement *> *achievements = player->GetAchievementList()->GetAchievements();
  7476. map<int32, Achievement *>::iterator itr;
  7477. Achievement *achievement;
  7478. vector<AchievementRequirements *> *requirements = 0;
  7479. vector<AchievementRequirements *>::iterator itr2;
  7480. AchievementRequirements *requirement;
  7481. vector<AchievementRewards *> *rewards = 0;
  7482. vector<AchievementRewards *>::iterator itr3;
  7483. AchievementRewards *reward;
  7484. PacketStruct *packet;
  7485. int16 i = 0;
  7486. int16 j = 0;
  7487. int16 k = 0;
  7488. if (!(packet = configReader.getStruct("WS_CharacterAchievements", version))) {
  7489. return;
  7490. }
  7491. packet->setArrayLengthByName("num_achievements" , achievements->size());
  7492. for (itr = achievements->begin(); itr != achievements->end(); itr++) {
  7493. achievement = itr->second;
  7494. packet->setArrayDataByName("achievement_id", achievement->GetID(), i);
  7495. packet->setArrayDataByName("title", achievement->GetTitle(), i);
  7496. packet->setArrayDataByName("uncompleted_text", achievement->GetUncompletedText(), i);
  7497. packet->setArrayDataByName("completed_text", achievement->GetCompletedText(), i);
  7498. packet->setArrayDataByName("category", achievement->GetCategory(), i);
  7499. packet->setArrayDataByName("expansion", achievement->GetExpansion(), i);
  7500. packet->setArrayDataByName("icon", achievement->GetIcon(), i);
  7501. packet->setArrayDataByName("point_value", achievement->GetPointValue(), i);
  7502. packet->setArrayDataByName("qty_req", achievement->GetQtyReq(), i);
  7503. packet->setArrayDataByName("hide_achievement", achievement->GetHide(), i);
  7504. packet->setArrayDataByName("unknown3", achievement->GetUnknown3a(), i);
  7505. packet->setArrayDataByName("unknown3", achievement->GetUnknown3b(), i);
  7506. requirements = achievement->GetRequirements();
  7507. rewards = achievement->GetRewards();
  7508. j = 0;
  7509. k = 0;
  7510. packet->setSubArrayLengthByName("num_items", requirements->size(), i, j);
  7511. for (itr2 = requirements->begin(); itr2 != requirements->end(); itr2++) {
  7512. requirement = *itr2;
  7513. packet->setSubArrayDataByName("item_name", requirement->name.c_str(), i, j);
  7514. packet->setSubArrayDataByName("item_qty_req", requirement->qty_req, i, j);
  7515. j++;
  7516. }
  7517. packet->setSubArrayLengthByName("num_rewards", achievement->GetRewards()->size(), i, k);
  7518. for (itr3 = rewards->begin(); itr3 != rewards->end(); itr3++) {
  7519. reward = *itr3;
  7520. packet->setSubArrayDataByName("reward_item", reward->reward.c_str(), i, k);
  7521. k++;
  7522. }
  7523. i++;
  7524. }
  7525. //packet->PrintPacket();
  7526. EQ2Packet* data = packet->serialize();
  7527. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  7528. safe_delete(packet);
  7529. safe_delete(data);
  7530. //DumpPacket(app);
  7531. QueuePacket(app);*/
  7532. QueuePacket(master_achievement_list.GetAchievementPacket()->Copy());
  7533. SendAchievementUpdate(true);
  7534. }
  7535. void Client::SendAchievementUpdate(bool first_login) {
  7536. map<int32, AchievementUpdate*>* updates = player->GetAchievementUpdateList()->GetAchievementUpdates();
  7537. map<int32, AchievementUpdate*>::iterator itr;
  7538. AchievementUpdate* update;
  7539. vector<AchievementUpdateItems*>* update_items = 0;
  7540. vector<AchievementUpdateItems*>::iterator itr2;
  7541. AchievementUpdateItems* update_item;
  7542. int16 i = 0;
  7543. int16 j = 0;
  7544. PacketStruct* packet;
  7545. if (!(packet = configReader.getStruct("WS_AchievementUpdate", version))) {
  7546. return;
  7547. }
  7548. packet->setDataByName("unknown1", first_login ? 1 : 0);
  7549. packet->setArrayLengthByName("num_achievements", updates->size());
  7550. for (itr = updates->begin(); itr != updates->end(); itr++) {
  7551. update = itr->second;
  7552. packet->setArrayDataByName("achievement_id", update->GetID(), i);
  7553. packet->setArrayDataByName("completed_date", update->GetCompletedDate(), i);
  7554. update_items = update->GetUpdateItems();
  7555. j = 0;
  7556. packet->setSubArrayLengthByName("num_items", update_items->size(), i);
  7557. for (itr2 = update_items->begin(); itr2 != update_items->end(); itr2++) {
  7558. update_item = *itr2;
  7559. packet->setSubArrayDataByName("item_update", update_item->item_update, i, j);
  7560. j++;
  7561. }
  7562. i++;
  7563. }
  7564. //packet->PrintPacket();
  7565. EQ2Packet* data = packet->serialize();
  7566. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  7567. safe_delete(packet);
  7568. safe_delete(data);
  7569. //DumpPacket(app);
  7570. QueuePacket(app);
  7571. }
  7572. void Client::SendBuyMerchantList(bool sell) {
  7573. Spawn* spawn = GetMerchantTransaction();
  7574. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  7575. vector<MerchantItemInfo>* items = world.GetMerchantItemList(spawn->GetMerchantID(), spawn->GetMerchantType(), player);
  7576. if (items) {
  7577. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7578. if (packet) {
  7579. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  7580. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7581. packet->setArrayLengthByName("num_items", items->size());
  7582. vector<MerchantItemInfo>::iterator itr;
  7583. sint8 item_difficulty = 0;
  7584. int32 sell_price = 0;
  7585. int i = 0;
  7586. int tmp_level = 0;
  7587. for (itr = items->begin(); itr != items->end(); itr++, i++) {
  7588. MerchantItemInfo ItemInfo = *itr;
  7589. Item* item = master_item_list.GetItem(ItemInfo.item_id);
  7590. if (!item)
  7591. continue;
  7592. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  7593. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7594. packet->setArrayDataByName("stack_size", item->stack_count, i);
  7595. packet->setArrayDataByName("icon", item->details.icon, i);
  7596. if (item->generic_info.adventure_default_level > 0)
  7597. tmp_level = item->generic_info.adventure_default_level;
  7598. else
  7599. tmp_level = item->generic_info.tradeskill_default_level;
  7600. packet->setArrayDataByName("level", tmp_level, i);
  7601. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  7602. packet->setArrayDataByName("tier", item->details.tier, i);
  7603. }
  7604. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  7605. item_difficulty = player->GetArrowColor(tmp_level);
  7606. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7607. item_difficulty = ARROW_COLOR_WHITE;
  7608. sint64 overrideValue = 0;
  7609. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "item_difficulty", item, player, nullptr, &overrideValue))
  7610. item_difficulty = (sint8)overrideValue;
  7611. item_difficulty -= 6;
  7612. if (item_difficulty < 0)
  7613. item_difficulty *= -1;
  7614. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7615. packet->setArrayDataByName("quantity", ItemInfo.quantity, i);
  7616. packet->setArrayDataByName("unknown5", 255, i);
  7617. packet->setArrayDataByName("stack_size2", item->stack_count, i);
  7618. sint64 dispFlags = 0;
  7619. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "buy_display_flags", item, player, nullptr, &dispFlags))
  7620. packet->setArrayDataByName("display_flags", (int8)dispFlags, i);
  7621. std::string overrideValueStr;
  7622. // 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)
  7623. if (GetVersion() >= 546 && item->GetItemScript() && lua_interface && lua_interface->RunItemScriptWithReturnString(item->GetItemScript(), "item_description", item, player, &overrideValueStr))
  7624. packet->setArrayDataByName("description", overrideValueStr.c_str(), i);
  7625. // If no price set in the merchant_inventory table then use the old method
  7626. if (ItemInfo.price_item_id == 0 && ItemInfo.price_item2_id == 0 && ItemInfo.price_coins == 0 && ItemInfo.price_status == 0 && ItemInfo.price_stationcash == 0) {
  7627. sell_price = (int32)(item->sell_price * multiplier);
  7628. packet->setArrayDataByName("price", sell_price, i);
  7629. }
  7630. else {
  7631. int8 count = 0;
  7632. if (ItemInfo.price_item_id != 0 && ItemInfo.price_item_qty != 0)
  7633. count++;
  7634. if (ItemInfo.price_item2_id != 0 && ItemInfo.price_item2_qty != 0)
  7635. count++;
  7636. if (count != 0) {
  7637. packet->setSubArrayLengthByName("num_tokens", count, i);
  7638. int8 index = 0;
  7639. Item* token = 0;
  7640. if (ItemInfo.price_item_id != 0) {
  7641. token = master_item_list.GetItem(ItemInfo.price_item_id);
  7642. if (item) {
  7643. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  7644. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item_qty, i, index);
  7645. packet->setSubArrayDataByName("token_id", ItemInfo.price_item_id, i, index);
  7646. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  7647. }
  7648. token = 0;
  7649. index++;
  7650. }
  7651. if (ItemInfo.price_item2_id != 0) {
  7652. token = master_item_list.GetItem(ItemInfo.price_item2_id);
  7653. if (item) {
  7654. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  7655. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item2_qty, i, index);
  7656. packet->setSubArrayDataByName("token_id", ItemInfo.price_item2_id, i, index);
  7657. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  7658. }
  7659. }
  7660. }
  7661. packet->setArrayDataByName("price", ItemInfo.price_coins, i);
  7662. packet->setArrayDataByName("status2", ItemInfo.price_status, i);
  7663. packet->setArrayDataByName("station_cash", ItemInfo.price_stationcash, i);
  7664. }
  7665. }
  7666. if (GetVersion() < 561) {
  7667. //buy is 0 so dont need to set it
  7668. if (sell)
  7669. packet->setDataByName("type", 1);
  7670. }
  7671. else if (GetVersion() == 561) {
  7672. packet->setDataByName("type", 2);
  7673. }
  7674. else {
  7675. if (sell)
  7676. packet->setDataByName("type", 130);
  7677. else
  7678. packet->setDataByName("type", 2);
  7679. }
  7680. EQ2Packet* outapp = packet->serialize();
  7681. QueuePacket(outapp);
  7682. safe_delete(packet);
  7683. }
  7684. safe_delete(items);
  7685. }
  7686. else {
  7687. // Need to send an empty packet in the event there is no item list, otherwise the
  7688. // last item list sent to the player will show for this merchant
  7689. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7690. if (packet) {
  7691. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7692. if (GetVersion() <= 561) {
  7693. //buy is 0 so dont need to set it
  7694. if (sell)
  7695. packet->setDataByName("type", 1);
  7696. }
  7697. else {
  7698. if (sell)
  7699. packet->setDataByName("type", 130);
  7700. else
  7701. packet->setDataByName("type", 2);
  7702. }
  7703. EQ2Packet* outapp = packet->serialize();
  7704. QueuePacket(outapp);
  7705. safe_delete(packet);
  7706. }
  7707. }
  7708. }
  7709. }
  7710. void Client::SendSellMerchantList(bool sell) {
  7711. Spawn* spawn = GetMerchantTransaction();
  7712. if (!spawn || (spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY) || (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO))
  7713. return;
  7714. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  7715. map<int32, Item*>* items = player->GetItemList();
  7716. if (items) {
  7717. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7718. if (packet) {
  7719. vector<Item*> sellable_items;
  7720. map<int32, Item*>::iterator test_itr;
  7721. for (test_itr = items->begin(); test_itr != items->end(); test_itr++) {
  7722. bool isbagwithitems = false;
  7723. 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))
  7724. isbagwithitems = true;
  7725. 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))
  7726. sellable_items.push_back(test_itr->second);
  7727. }
  7728. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7729. packet->setArrayLengthByName("num_items", sellable_items.size());
  7730. vector<Item*>::iterator itr;
  7731. Item* item = 0;
  7732. sint8 item_difficulty = 0;
  7733. float multiplier = CalculateSellMultiplier(spawn->GetMerchantID());
  7734. int32 sell_price = 0;
  7735. Item* master_item = 0;
  7736. int i = 0;
  7737. int tmp_level = 0;
  7738. for (itr = sellable_items.begin(); itr != sellable_items.end(); itr++, i++) {
  7739. item = *itr;
  7740. master_item = master_item_list.GetItem(item->details.item_id);
  7741. if (master_item)
  7742. sell_price = (int32)(master_item->sell_price * multiplier);
  7743. else
  7744. sell_price = 0;
  7745. if (sell_price > item->sell_price)
  7746. sell_price = item->sell_price;
  7747. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  7748. string thename = item->name;
  7749. packet->setArrayDataByName("price", sell_price, i);
  7750. packet->setArrayDataByName("status", 0, i);//additive to status 2 maybe for server bonus etc
  7751. int8 dispFlags = 0;
  7752. // only city merchants allow selling for status
  7753. if(item->sell_status > 0 && (spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT))
  7754. {
  7755. packet->setArrayDataByName("status2", item->sell_status, i); //this one is the main status
  7756. int32 guildMaxLevel = 5 + item->details.recommended_level; // client hard codes +5 to the level
  7757. if (GetPlayer()->GetGuild() && GetPlayer()->GetGuild()->GetLevel() >= guildMaxLevel) {
  7758. dispFlags += DISPLAY_FLAG_NO_GUILD_STATUS;
  7759. }
  7760. }
  7761. if(item->no_buy_back || (item->sell_status > 0 && (spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))
  7762. {
  7763. if(GetVersion() < 1188)
  7764. 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
  7765. else
  7766. dispFlags += DISPLAY_FLAG_NO_BUYBACK;
  7767. }
  7768. if(item->no_sale)
  7769. dispFlags += DISPLAY_FLAG_NOT_FOR_SALE;
  7770. packet->setArrayDataByName("display_flags", dispFlags, i);
  7771. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7772. packet->setArrayDataByName("unique_item_id", item->details.unique_id, i);
  7773. packet->setArrayDataByName("stack_size", item->details.count, i);
  7774. packet->setArrayDataByName("icon", item->details.icon, i);
  7775. if (item->generic_info.adventure_default_level > 0)
  7776. tmp_level = item->generic_info.adventure_default_level;
  7777. else
  7778. tmp_level = item->generic_info.tradeskill_default_level;
  7779. packet->setArrayDataByName("level", item->details.recommended_level, i);
  7780. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  7781. packet->setArrayDataByName("tier", item->details.tier, i);
  7782. }
  7783. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  7784. item_difficulty = player->GetArrowColor(tmp_level);
  7785. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7786. item_difficulty = ARROW_COLOR_WHITE;
  7787. sint64 overrideValue = 0;
  7788. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "item_difficulty", item, player, nullptr, &overrideValue))
  7789. item_difficulty = (sint8)overrideValue;
  7790. item_difficulty -= 6;
  7791. if (item_difficulty < 0)
  7792. item_difficulty *= -1;
  7793. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7794. if (item->details.count == 1)
  7795. packet->setArrayDataByName("quantity", 0xFFFF, i);
  7796. else
  7797. packet->setArrayDataByName("quantity", item->details.count, i);
  7798. packet->setArrayDataByName("stack_size2", item->details.count, i);
  7799. if (GetVersion() <= 1096)
  7800. packet->setArrayDataByName("description", item->description.c_str(), i);
  7801. }
  7802. if (GetVersion() < 561) {
  7803. packet->setDataByName("type", 1);
  7804. }
  7805. else if(GetVersion() == 561) {
  7806. packet->setDataByName("type", 1);
  7807. }
  7808. else {
  7809. if (sell)
  7810. packet->setDataByName("type", 129);
  7811. else
  7812. packet->setDataByName("type", 1);
  7813. }
  7814. packet->setDataByName("unknown8a", 16256, 6);
  7815. packet->setDataByName("unknown8a", 16256, 10);
  7816. //packet->PrintPacket();
  7817. EQ2Packet* outapp = packet->serialize();
  7818. //DumpPacket(outapp);
  7819. QueuePacket(outapp);
  7820. safe_delete(packet);
  7821. }
  7822. safe_delete(items);
  7823. }
  7824. }
  7825. }
  7826. void Client::SendBuyBackList(bool sell) {
  7827. if (GetVersion() <= 561) //this wasn't added until LU37 on July 31st 2007, well after the DoF client
  7828. return;
  7829. Spawn* spawn = GetMerchantTransaction();
  7830. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  7831. deque<BuyBackItem*>::iterator itr;
  7832. int i = 0;
  7833. Item* master_item = 0;
  7834. BuyBackItem* buyback = 0;
  7835. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7836. if (packet) {
  7837. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7838. packet->setArrayLengthByName("num_items", buy_back_items.size());
  7839. sint8 item_difficulty = 0;
  7840. MBuyBack.readlock(__FUNCTION__, __LINE__);
  7841. int tmp_level = 0;
  7842. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++, i++) {
  7843. buyback = *itr;
  7844. master_item = master_item_list.GetItem(buyback->item_id);
  7845. if (master_item) {
  7846. packet->setArrayDataByName("item_name", master_item->name.c_str(), i);
  7847. packet->setArrayDataByName("price", buyback->price, i);
  7848. packet->setArrayDataByName("item_id", master_item->details.item_id, i);
  7849. packet->setArrayDataByName("unique_item_id", buyback->unique_id, i);
  7850. packet->setArrayDataByName("stack_size", buyback->quantity, i);
  7851. packet->setArrayDataByName("icon", master_item->details.icon, i);
  7852. if (master_item->generic_info.adventure_default_level > 0)
  7853. tmp_level = master_item->generic_info.adventure_default_level;
  7854. else
  7855. tmp_level = master_item->generic_info.tradeskill_default_level;
  7856. packet->setArrayDataByName("level", tmp_level, i);
  7857. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  7858. packet->setArrayDataByName("tier", master_item->details.tier, i);
  7859. }
  7860. packet->setArrayDataByName("item_id2", master_item->details.item_id, i);
  7861. item_difficulty = player->GetArrowColor(tmp_level);
  7862. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7863. item_difficulty = ARROW_COLOR_WHITE;
  7864. sint64 overrideValue = 0;
  7865. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "item_difficulty", master_item, player, nullptr, &overrideValue))
  7866. item_difficulty = (sint8)overrideValue;
  7867. item_difficulty -= 6;
  7868. if (item_difficulty < 0)
  7869. item_difficulty *= -1;
  7870. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7871. sint64 dispFlags = 0;
  7872. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "buyback_display_flags", master_item, player, nullptr, &dispFlags))
  7873. packet->setArrayDataByName("display_flags", (int8)dispFlags, i);
  7874. if (buyback->quantity == 1)
  7875. packet->setArrayDataByName("quantity", 0xFFFF, i);
  7876. else
  7877. packet->setArrayDataByName("quantity", buyback->quantity, i);
  7878. packet->setArrayDataByName("stack_size2", buyback->quantity, i);
  7879. if (GetVersion() <= 1096)
  7880. packet->setArrayDataByName("description", master_item->description.c_str(), i);
  7881. }
  7882. }
  7883. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  7884. if (sell)
  7885. packet->setDataByName("type", 640);
  7886. else
  7887. packet->setDataByName("type", 512);
  7888. EQ2Packet* outapp = packet->serialize();
  7889. // DumpPacket(outapp);
  7890. QueuePacket(outapp);
  7891. safe_delete(packet);
  7892. }
  7893. }
  7894. }
  7895. void Client::SendRepairList() {
  7896. Spawn* spawn = GetMerchantTransaction();
  7897. if (spawn) {
  7898. vector<Item*>* repairable_items = GetRepairableItems();
  7899. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7900. if (packet) {
  7901. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7902. packet->setArrayLengthByName("num_items", repairable_items->size());
  7903. Item* item = 0;
  7904. sint8 item_difficulty = 0;
  7905. int32 i = 0;
  7906. vector<Item*>::iterator itr;
  7907. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++, i++) {
  7908. item = *itr;
  7909. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  7910. packet->setArrayDataByName("price", item->CalculateRepairCost(), i);
  7911. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7912. packet->setArrayDataByName("stack_size", item->details.count, i);
  7913. packet->setArrayDataByName("icon", item->details.icon, i);
  7914. /*if (item->generic_info.adventure_default_level > 0)
  7915. tmp_level = item->generic_info.adventure_default_level;
  7916. else
  7917. tmp_level = item->generic_info.tradeskill_default_level;
  7918. packet->setArrayDataByName("level", tmp_level, i);*/
  7919. packet->setArrayDataByName("level", item->generic_info.adventure_default_level, i);
  7920. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  7921. packet->setArrayDataByName("tier", item->details.tier, i);
  7922. }
  7923. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  7924. item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  7925. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7926. item_difficulty = ARROW_COLOR_WHITE;
  7927. item_difficulty -= 6;
  7928. if (item_difficulty < 0)
  7929. item_difficulty *= -1;
  7930. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7931. if (item->details.count == 1)
  7932. packet->setArrayDataByName("quantity", 0xFFFF, i);
  7933. else
  7934. packet->setArrayDataByName("quantity", item->details.count, i);
  7935. packet->setArrayDataByName("stack_size2", item->details.count, i);
  7936. if (GetVersion() <= 1096)
  7937. packet->setArrayDataByName("description", item->description.c_str(), i);
  7938. }
  7939. if (GetVersion() <= 561) {
  7940. packet->setDataByName("type", 112);
  7941. }
  7942. else {
  7943. packet->setDataByName("type", 96);
  7944. }
  7945. EQ2Packet* outapp = packet->serialize();
  7946. //DumpPacket(outapp);
  7947. QueuePacket(outapp);
  7948. /*if (GetVersion() <= 561) {
  7949. packet->setDataByName("type", 16);
  7950. EQ2Packet* outapp2 = packet->serialize();
  7951. QueuePacket(outapp2);
  7952. }*/
  7953. safe_delete(packet);
  7954. }
  7955. safe_delete(repairable_items);
  7956. }
  7957. }
  7958. void Client::ShowLottoWindow() {
  7959. if(GetVersion() <= 373) {
  7960. SimpleMessage(CHANNEL_COLOR_RED, "This client does not support the gambler UI, only Desert of Flames or later client.");
  7961. return;
  7962. }
  7963. Spawn* spawn = GetMerchantTransaction();
  7964. if (spawn) {
  7965. int32 item_id = rule_manager.GetGlobalRule(R_World, GamblingTokenItemID)->GetInt32();
  7966. if (!item_id)
  7967. {
  7968. LogWrite(WORLD__ERROR, 0, "World", "No GamblingTokenItemID rule set!");
  7969. SimpleMessage(CHANNEL_COLOR_RED, "The server admin has not setup a lotto item ticket.");
  7970. return;
  7971. }
  7972. else if (item_id == 0)
  7973. {
  7974. LogWrite(WORLD__ERROR, 0, "World", "Error! Invalid GamblingTokenItemID value!");
  7975. return;
  7976. }
  7977. Item* item = master_item_list.GetItem(item_id);
  7978. if (!item) {
  7979. LogWrite(WORLD__ERROR, 0, "World", "The 'GamblingTokenItemID' rule value %u is not a valid item id.", item_id);
  7980. return;
  7981. }
  7982. LogWrite(WORLD__DEBUG, 0, "World", "GamblingTokenItemID = '%s' (%u)", item->name.c_str(), item_id);
  7983. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7984. if (packet) {
  7985. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7986. packet->setArrayLengthByName("num_items", 1);
  7987. packet->setArrayDataByName("item_name", item->name.c_str());
  7988. packet->setArrayDataByName("price", item->sell_price);
  7989. packet->setArrayDataByName("item_id", item->details.item_id);
  7990. packet->setArrayDataByName("stack_size", item->details.count);
  7991. packet->setArrayDataByName("icon", item->details.icon);
  7992. packet->setArrayDataByName("level", item->generic_info.adventure_default_level);
  7993. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  7994. packet->setArrayDataByName("tier", item->details.tier);
  7995. }
  7996. packet->setArrayDataByName("item_id2", item->details.item_id);
  7997. int8 item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  7998. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7999. item_difficulty = ARROW_COLOR_WHITE;
  8000. item_difficulty -= 6;
  8001. if (item_difficulty < 0)
  8002. item_difficulty *= -1;
  8003. packet->setArrayDataByName("item_difficulty", item_difficulty);
  8004. //if(item->details.count == 1)
  8005. packet->setArrayDataByName("quantity", 0xFFFF);
  8006. //else
  8007. // packet->setArrayDataByName("quantity", item->details.count);
  8008. packet->setArrayDataByName("stack_size2", item->details.count);
  8009. packet->setArrayDataByName("description", item->description.c_str());
  8010. if (GetVersion() <= 546) {
  8011. packet->setDataByName("type", 128);
  8012. }
  8013. else {
  8014. packet->setDataByName("type", 0x00000102);
  8015. }
  8016. QueuePacket(packet->serialize());
  8017. safe_delete(packet);
  8018. }
  8019. }
  8020. }
  8021. void Client::PlayLotto(int32 price, int32 ticket_item_id) {
  8022. PacketStruct* packet = configReader.getStruct("WS_Lottery", GetVersion());
  8023. if (packet) {
  8024. world.AddLottoPlayer(GetCharacterID(), Timer::GetCurrentTime2() + 4500);
  8025. int32 rolls[6] = { 0 };
  8026. int32 lottery_digits[6] = { 0 };
  8027. int8 num_matches = 0;
  8028. int64 jackpot = 0;
  8029. Item* item = GetPlayer()->item_list.GetItemFromID(ticket_item_id);
  8030. if (!item) {
  8031. return;
  8032. }
  8033. database.DeleteItem(GetCharacterID(), item, 0);
  8034. GetPlayer()->item_list.RemoveItem(item, true);
  8035. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  8036. Variable* winning_numbers = variables.FindVariable("gambling_winning_numbers");
  8037. if (!winning_numbers) {
  8038. winning_numbers = new Variable("gambling_winning_numbers", "231205182236", "Current Gigglegibber Gambling Game winning numbers");
  8039. variables.AddVariable(winning_numbers);
  8040. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  8041. }
  8042. if (strlen(winning_numbers->GetValue()) != 12) {
  8043. winning_numbers->SetValue("231205182236");
  8044. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  8045. }
  8046. try {
  8047. for (int32 i = 0; i < 12; i += 2) {
  8048. char num[4];
  8049. strncpy(num, winning_numbers->GetValue() + i, 2);
  8050. lottery_digits[i / 2] = atoi(num);
  8051. }
  8052. }
  8053. catch (...) {
  8054. LogWrite(WORLD__ERROR, 0, "World", "Error parsing 'gambling_winning_numbers' variable");
  8055. return;
  8056. }
  8057. Variable* jackpot_var = variables.FindVariable("gambling_current_jackpot");
  8058. if (!jackpot_var) {
  8059. jackpot_var = new Variable("gambling_current_jackpot", "10000", "Current Gigglegibber Gambling Game Jackpot");
  8060. variables.AddVariable(jackpot_var);
  8061. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  8062. }
  8063. try {
  8064. jackpot = atoul(jackpot_var->GetValue());
  8065. if (jackpot < 10000)
  8066. jackpot = 10000;
  8067. }
  8068. catch (...) {
  8069. jackpot = 10000;
  8070. }
  8071. char new_jackpot[128] = { 0 };
  8072. sprintf(new_jackpot, "%llu", jackpot + price);
  8073. jackpot_var->SetValue(new_jackpot);
  8074. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  8075. world.PickRandomLottoDigits(rolls);
  8076. packet->setDataByName("roll_digit1", rolls[0]);
  8077. packet->setDataByName("roll_digit2", rolls[1]);
  8078. packet->setDataByName("roll_digit3", rolls[2]);
  8079. packet->setDataByName("roll_digit4", rolls[3]);
  8080. packet->setDataByName("roll_digit5", rolls[4]);
  8081. packet->setDataByName("roll_digit6", rolls[5]);
  8082. packet->setDataByName("lottery_digit1", lottery_digits[0]);
  8083. packet->setDataByName("lottery_digit2", lottery_digits[1]);
  8084. packet->setDataByName("lottery_digit3", lottery_digits[2]);
  8085. packet->setDataByName("lottery_digit4", lottery_digits[3]);
  8086. packet->setDataByName("lottery_digit5", lottery_digits[4]);
  8087. packet->setDataByName("lottery_digit6", lottery_digits[5]);
  8088. QueuePacket(packet->serialize());
  8089. safe_delete(packet);
  8090. for (int32 i = 0; i < 6; i++) {
  8091. for (int32 j = 0; j < 6; j++) {
  8092. if (rolls[i] == lottery_digits[j]) {
  8093. num_matches++;
  8094. break;
  8095. }
  8096. }
  8097. }
  8098. char new_jackpot_str[16];
  8099. memset(new_jackpot_str, 0, sizeof(new_jackpot_str));
  8100. world.SetLottoPlayerNumMatches(GetCharacterID(), num_matches);
  8101. if (num_matches == 6) {
  8102. world.PickRandomLottoDigits(lottery_digits);
  8103. for (int32 i = 0; i < 12; i += 2)
  8104. sprintf(new_jackpot_str + i, "%02d", lottery_digits[i / 2]);
  8105. winning_numbers->SetValue(new_jackpot_str);
  8106. jackpot_var->SetValue("10000");
  8107. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  8108. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  8109. }
  8110. }
  8111. }
  8112. void Client::SendGuildCreateWindow() {
  8113. if (GetVersion() <= 561) {
  8114. SimpleMessage(0, "Not implemented on this client...yet?");
  8115. }
  8116. else {
  8117. Spawn* spawn = GetPlayer()->GetTarget();
  8118. if (spawn) {
  8119. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  8120. if (packet) {
  8121. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  8122. packet->setArrayLengthByName("num_items", 0);
  8123. packet->setDataByName("type", 0x00008000);
  8124. QueuePacket(packet->serialize());
  8125. safe_delete(packet);
  8126. }
  8127. }
  8128. }
  8129. }
  8130. void Client::AddBuyBack(int32 unique_id, int32 item_id, int16 quantity, int32 price, bool save_needed) {
  8131. BuyBackItem* item = new BuyBackItem;
  8132. item->item_id = item_id;
  8133. item->unique_id = unique_id;
  8134. item->price = price;
  8135. item->quantity = quantity;
  8136. item->save_needed = save_needed;
  8137. MBuyBack.writelock(__FUNCTION__, __LINE__);
  8138. buy_back_items.push_back(item);
  8139. if (buy_back_items.size() > 10) {
  8140. safe_delete(buy_back_items.front());
  8141. buy_back_items.pop_front();
  8142. }
  8143. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  8144. }
  8145. deque<BuyBackItem*>* Client::GetBuyBacks() {
  8146. return &buy_back_items;
  8147. }
  8148. vector<Item*>* Client::GetRepairableItems() {
  8149. vector<Item*>* repairable_items = new vector<Item*>;
  8150. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  8151. map<int32, Item*>* items = player->GetItemList();
  8152. if (equipped_items && equipped_items->size() > 0) {
  8153. for (int32 i = 0; i < equipped_items->size(); i++) {
  8154. Item* item = equipped_items->at(i);
  8155. if (item && !item->CheckFlag2(NO_REPAIR) && item->generic_info.condition < 100)
  8156. repairable_items->push_back(item);
  8157. }
  8158. }
  8159. if (items && items->size() > 0) {
  8160. map<int32, Item*>::iterator itr;
  8161. for (itr = items->begin(); itr != items->end(); itr++) {
  8162. Item* item = itr->second;
  8163. if (item && !item->CheckFlag2(NO_REPAIR) && item->generic_info.condition < 100)
  8164. repairable_items->push_back(item);
  8165. }
  8166. }
  8167. safe_delete(equipped_items);
  8168. safe_delete(items);
  8169. return repairable_items;
  8170. }
  8171. vector<Item*>* Client::GetItemsByEffectType(ItemEffectType type, ItemEffectType type2) {
  8172. if(type == NO_EFFECT_TYPE)
  8173. return nullptr;
  8174. vector<Item*>* return_items = new vector<Item*>;
  8175. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  8176. map<int32, Item*>* items = player->GetItemList();
  8177. if (equipped_items && equipped_items->size() > 0) {
  8178. for (int32 i = 0; i < equipped_items->size(); i++) {
  8179. Item* item = equipped_items->at(i);
  8180. if (item && (item->effect_type == type || (type2 != NO_EFFECT_TYPE && item->effect_type == type2)))
  8181. return_items->push_back(item);
  8182. }
  8183. }
  8184. if (items && items->size() > 0) {
  8185. map<int32, Item*>::iterator itr;
  8186. for (itr = items->begin(); itr != items->end(); itr++) {
  8187. Item* item = itr->second;
  8188. if (item && (item->effect_type == type || (type2 != NO_EFFECT_TYPE && item->effect_type == type2)))
  8189. return_items->push_back(item);
  8190. }
  8191. }
  8192. safe_delete(equipped_items);
  8193. safe_delete(items);
  8194. return return_items;
  8195. }
  8196. void Client::SendMailList() {
  8197. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  8198. if (kiosk_id > 0) {
  8199. PacketStruct* p = configReader.getStruct("WS_GetMailHeader", GetVersion());
  8200. if (p) {
  8201. MutexMap<int32, Mail*>* mail_list = player->GetMail();
  8202. MutexMap<int32, Mail*>::iterator itr = mail_list->begin();
  8203. int32 i = 0;
  8204. p->setDataByName("kiosk_id", kiosk_id);
  8205. p->setArrayLengthByName("num_messages", (int16)mail_list->size());
  8206. while (itr.Next()) {
  8207. Mail* mail = itr->second;
  8208. p->setArrayDataByName("mail_id", mail->mail_id, i);
  8209. p->setArrayDataByName("player_to_id", mail->player_to_id, i);
  8210. p->setArrayDataByName("player_from", mail->player_from.c_str(), i);
  8211. p->setArrayDataByName("subject", mail->subject.c_str(), i);
  8212. p->setArrayDataByName("already_read", mail->already_read, i);
  8213. if(mail->expire_time)
  8214. p->setArrayDataByName("mail_deletion", mail->expire_time - mail->time_sent, i);
  8215. else
  8216. p->setArrayDataByName("mail_deletion", 0, i);
  8217. p->setArrayDataByName("mail_type", mail->mail_type, i);
  8218. p->setArrayDataByName("mail_expire", 0xFFFFFFFF, i);
  8219. p->setArrayDataByName("unknown1a", 0xFFFFFFFF, i);
  8220. p->setArrayDataByName("coin_copper", mail->coin_copper, i);
  8221. p->setArrayDataByName("coin_silver", mail->coin_silver, i);
  8222. p->setArrayDataByName("coin_gold", mail->coin_gold, i);
  8223. p->setArrayDataByName("coin_plat", mail->coin_plat, i);
  8224. //p->setArrayDataByName("unknown2", 0, i);
  8225. bool successItemAdd = false;
  8226. if(mail->stack || mail->char_item_id)
  8227. {
  8228. Item* item = master_item_list.GetItem(mail->char_item_id);
  8229. if(item)
  8230. {
  8231. item->stack_count = mail->stack > 1 ? mail->stack : 0;
  8232. if (version < 860)
  8233. p->setItemArrayDataByName("item", item, player, i, 0, GetClientItemPacketOffset());
  8234. else if (version < 1193)
  8235. p->setItemArrayDataByName("item", item, player, i);
  8236. else
  8237. p->setItemArrayDataByName("item", item, player, i, 0, 2);
  8238. successItemAdd = true;
  8239. }
  8240. }
  8241. if(!successItemAdd)
  8242. {
  8243. p->setArrayDataByName("end_tag2", GetItemPacketType(GetVersion()), i);
  8244. p->setArrayDataByName("end_tag3", 0xFF, i);
  8245. }
  8246. i++;
  8247. }
  8248. // GMs send mail for free!
  8249. if (GetAdminStatus() > 0)
  8250. {
  8251. p->setDataByName("postage_cost", 0);
  8252. p->setDataByName("attachment_cost", 0);
  8253. }
  8254. else
  8255. {
  8256. p->setDataByName("postage_cost", 10);
  8257. p->setDataByName("attachment_cost", 50);
  8258. }
  8259. p->setDataByName("unknown3", 0x01F4);
  8260. p->setDataByName("unknown4", 0x01000000);
  8261. EQ2Packet* pack = p->serialize();
  8262. //DumpPacket(pack);
  8263. QueuePacket(pack);
  8264. safe_delete(p);
  8265. }
  8266. }
  8267. else
  8268. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8269. }
  8270. void Client::DisplayMailMessage(int32 mail_id) {
  8271. Mail* mail = player->GetMail(mail_id);
  8272. if (mail) {
  8273. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  8274. if (kiosk_id > 0) {
  8275. PacketStruct* update = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8276. if (update) {
  8277. update->setDataByName("action", 0x03);
  8278. update->setDataByName("packettype", GetItemPacketType(GetVersion()));
  8279. update->setDataByName("packetsubtype", 0xFF);
  8280. QueuePacket(update->serialize());
  8281. safe_delete(update);
  8282. }
  8283. if(!mail->already_read) {
  8284. mail->already_read = true;
  8285. SendMailList();
  8286. }
  8287. PacketStruct* packet = configReader.getStruct("WS_MailGetMessage", GetVersion());
  8288. if (packet) {
  8289. packet->setDataByName("kiosk_id", kiosk_id);
  8290. packet->setDataByName("mail_id", mail->mail_id);
  8291. packet->setDataByName("player_to_id", mail->player_to_id);
  8292. packet->setDataByName("player_from", mail->player_from.c_str());
  8293. packet->setDataByName("subject", mail->subject.c_str());
  8294. packet->setDataByName("mail_body", mail->mail_body.c_str());
  8295. packet->setDataByName("unknown1", 1);
  8296. packet->setDataByName("unknown2", 0);
  8297. packet->setDataByName("lock_report_button", 1);
  8298. packet->setDataByName("unknown3", 0xFFFFFFFF);
  8299. packet->setDataByName("unknown3a", 0xFFFFFFFF);
  8300. packet->setDataByName("coin_copper", mail->coin_copper);
  8301. packet->setDataByName("coin_silver", mail->coin_silver);
  8302. packet->setDataByName("coin_gold", mail->coin_gold);
  8303. packet->setDataByName("coin_plat", mail->coin_plat);
  8304. if(mail->stack || mail->char_item_id)
  8305. {
  8306. Item* item = master_item_list.GetItem(mail->char_item_id);
  8307. item->stack_count = mail->stack > 1 ? mail->stack : 0;
  8308. if (version < 860)
  8309. packet->setItemByName("item", item, player, 0, version <= 373 ? -2 : -1);
  8310. else if (version < 1193)
  8311. packet->setItemByName("item", item, player, 0, 0);
  8312. else
  8313. packet->setItemByName("item", item, player, 0, 2);
  8314. }
  8315. else
  8316. {
  8317. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  8318. packet->setDataByName("end_tag3", 0xFF);
  8319. }
  8320. mail->save_needed = true;
  8321. EQ2Packet* pack = packet->serialize();
  8322. QueuePacket(pack);
  8323. safe_delete(packet);
  8324. // trying to update this causes the window not to open
  8325. //SendMailList();
  8326. }
  8327. }
  8328. else
  8329. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8330. }
  8331. }
  8332. /* 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
  8333. packet back to the client before the mail actually sent. */
  8334. void Client::HandleSentMail(EQApplicationPacket* app) {
  8335. PacketStruct* packet = configReader.getStruct("WS_MailSendMessage", GetVersion());
  8336. if (packet) {
  8337. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  8338. string player_to = packet->getType_EQ2_16BitString_ByName("player_to").data;
  8339. PacketStruct* reply_packet = configReader.getStruct("WS_MailSendMessageReply", GetVersion());
  8340. vector<int32>* ids = 0;
  8341. MMailWindowMutex.lock();
  8342. if (reply_packet) {
  8343. int8 reply_type = MAIL_SEND_RESULT_UNKNOWN_ERROR;
  8344. if (player_to.length() == 0)
  8345. reply_type = MAIL_SEND_RESULT_EMPTY_TO_LIST;
  8346. else if (player_to.compare(string(GetPlayer()->GetName())) == 0)
  8347. reply_type = MAIL_SEND_RESULT_CANNOT_SEND_TO_SELF;
  8348. else if (GetAdminStatus() == 0 && !player->RemoveCoins(10))
  8349. reply_type = MAIL_SEND_RESULT_NOT_ENOUGH_COIN;
  8350. else {
  8351. if (GetAdminStatus() > 200 && player_to.compare("<all>") == 0) {
  8352. if (mail_window.char_item_id == 0 && (mail_window.coin_copper + mail_window.coin_silver + mail_window.coin_gold + mail_window.coin_plat) == 0)
  8353. ids = database.GetAllPlayerIDs();
  8354. else
  8355. SimpleMessage(CHANNEL_NARRATIVE, "You may not mail gifts to multiple players.");
  8356. }
  8357. else {
  8358. ids = new vector<int32>;
  8359. ids->push_back(database.GetCharacterID(player_to.c_str()));
  8360. }
  8361. if (ids) {
  8362. for (int32 i = 0; i < ids->size(); i++) {
  8363. int32 player_to_id = ids->at(i);
  8364. if (player_to_id > 0) {
  8365. reply_type = MAIL_SEND_RESULT_SUCCESS;
  8366. Mail* mail = new Mail;
  8367. mail->mail_id = 0;
  8368. mail->player_to_id = player_to_id;
  8369. mail->player_from = string(GetPlayer()->GetName());
  8370. mail->subject = packet->getType_EQ2_16BitString_ByName("subject").data;
  8371. mail->mail_body = packet->getType_EQ2_16BitString_ByName("mail_body").data;
  8372. mail->already_read = 0;
  8373. mail->mail_type = MAIL_TYPE_REGULAR;
  8374. mail->coin_copper = mail_window.coin_copper;
  8375. mail->coin_silver = mail_window.coin_silver;
  8376. mail->coin_gold = mail_window.coin_gold;
  8377. mail->coin_plat = mail_window.coin_plat;
  8378. mail->char_item_id = mail_window.char_item_id;
  8379. mail->stack = mail_window.stack;
  8380. // GM's send mail for free!
  8381. if (GetAdminStatus() > 0)
  8382. {
  8383. mail->postage_cost = 0;
  8384. mail->attachment_cost = 0;
  8385. }
  8386. else
  8387. {
  8388. mail->postage_cost = 10;
  8389. mail->attachment_cost = 50;
  8390. }
  8391. mail->time_sent = Timer::GetUnixTimeStamp();
  8392. mail->expire_time = mail->time_sent + 2592000; //30 days in seconds
  8393. mail->save_needed = false;
  8394. database.SavePlayerMail(mail);
  8395. Client* to_client = zone_list.GetClientByCharID(player_to_id);
  8396. if (to_client) {
  8397. to_client->GetPlayer()->AddMail(mail);
  8398. to_client->SimpleMessage(CHANNEL_NARRATIVE, "You have unread mail in your mailbox.");
  8399. string popup_text = "You have unread mail!";
  8400. to_client->SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  8401. }
  8402. else {
  8403. // don't need the pointer the client doesn't exist currently
  8404. safe_delete(mail);
  8405. }
  8406. ResetSendMail(false, false);
  8407. }
  8408. else
  8409. reply_type = MAIL_SEND_RESULT_UNKNOWN_PLAYER;
  8410. }
  8411. }
  8412. }
  8413. string players_to = "";
  8414. if (ids) {
  8415. for (int32 i = 0; i < ids->size(); i++) {
  8416. if (ids->at(i) != 0)
  8417. players_to.append(database.GetCharacterName(ids->at(i)));
  8418. if (i < (ids->size() - 1))
  8419. players_to.append(", ");
  8420. }
  8421. }
  8422. reply_packet->setDataByName("player_to", players_to.c_str());
  8423. reply_packet->setDataByName("reply_type", reply_type);
  8424. QueuePacket(reply_packet->serialize());
  8425. safe_delete(reply_packet);
  8426. safe_delete(ids);
  8427. }
  8428. MMailWindowMutex.unlock();
  8429. }
  8430. safe_delete(packet);
  8431. }
  8432. }
  8433. void Client::DeleteMail(int32 mail_id, bool from_database) {
  8434. player->DeleteMail(mail_id, from_database);
  8435. }
  8436. bool Client::AddMailItem(Item* item)
  8437. {
  8438. if(item && (item->CheckFlag(LORE) || item->CheckFlag(STACK_LORE))) {
  8439. Message(CHANNEL_COLOR_CHAT_RELATIONSHIP, "Lore items cannot be mailed.");
  8440. return false;
  8441. }
  8442. bool ret = false;
  8443. if (GetMailTransaction()) {
  8444. MMailWindowMutex.lock();
  8445. if(mail_window.char_item_id == 0)
  8446. {
  8447. mail_window.item = item;
  8448. mail_window.char_item_id = item->details.item_id;
  8449. mail_window.stack = item->details.count;
  8450. ret = true;
  8451. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8452. packet->setDataByName("coin_copper", mail_window.coin_copper);
  8453. packet->setDataByName("coin_silver", mail_window.coin_silver);
  8454. packet->setDataByName("coin_gold", mail_window.coin_gold);
  8455. packet->setDataByName("coin_plat", mail_window.coin_plat);
  8456. if(item)
  8457. {
  8458. packet->setDataByName("stack", mail_window.stack);
  8459. item->stack_count = mail_window.stack;
  8460. if (version < 860)
  8461. packet->setItemByName("item", item, player, 0, version <= 373 ? -2 : -1);
  8462. else if (version < 1193)
  8463. packet->setItemByName("item", item, player, 0, 0);
  8464. else
  8465. packet->setItemByName("item", item, player, 0, 2);
  8466. }
  8467. else
  8468. {
  8469. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  8470. packet->setDataByName("end_tag3", 0xFF);
  8471. }
  8472. QueuePacket(packet->serialize());
  8473. }
  8474. MMailWindowMutex.unlock();
  8475. }
  8476. return ret;
  8477. }
  8478. bool Client::AddMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  8479. bool ret = false;
  8480. if (GetMailTransaction()) {
  8481. MMailWindowMutex.lock();
  8482. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8483. if (packet) {
  8484. if (copper > 0) {
  8485. if (player->RemoveCoins(copper)) {
  8486. mail_window.coin_copper += copper;
  8487. Message(CHANNEL_NARRATIVE, "You add %u copper to the mail window.", copper);
  8488. ret = true;
  8489. }
  8490. }
  8491. else if (silver > 0) {
  8492. if (player->RemoveCoins(silver * 100)) {
  8493. mail_window.coin_silver += silver;
  8494. Message(CHANNEL_NARRATIVE, "You add %u silver to the mail window.", silver);
  8495. ret = true;
  8496. }
  8497. }
  8498. else if (gold > 0) {
  8499. if (player->RemoveCoins(gold * 10000)) {
  8500. mail_window.coin_gold += gold;
  8501. Message(CHANNEL_NARRATIVE, "You add %u gold to the mail window.", gold);
  8502. ret = true;
  8503. }
  8504. }
  8505. else if (plat > 0) {
  8506. if (player->RemoveCoins(plat * 1000000)) {
  8507. mail_window.coin_plat += plat;
  8508. Message(CHANNEL_NARRATIVE, "You add %u platinum to the mail window.", plat);
  8509. ret = true;
  8510. }
  8511. }
  8512. if (ret) {
  8513. packet->setDataByName("coin_copper", mail_window.coin_copper);
  8514. packet->setDataByName("coin_silver", mail_window.coin_silver);
  8515. packet->setDataByName("coin_gold", mail_window.coin_gold);
  8516. packet->setDataByName("coin_plat", mail_window.coin_plat);
  8517. Item* item = master_item_list.GetItem(mail_window.char_item_id);
  8518. if(item)
  8519. {
  8520. packet->setDataByName("stack", mail_window.stack);
  8521. item->stack_count = mail_window.stack;
  8522. if (version < 860)
  8523. packet->setItemByName("item", item, player, 0, version <= 373 ? -2 : -1);
  8524. else if (version < 1193)
  8525. packet->setItemByName("item", item, player, 0, 0);
  8526. else
  8527. packet->setItemByName("item", item, player, 0, 2);
  8528. }
  8529. else
  8530. {
  8531. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  8532. packet->setDataByName("end_tag3", 0xFF);
  8533. }
  8534. //packet->PrintPacket();
  8535. QueuePacket(packet->serialize());
  8536. }
  8537. else
  8538. SimpleMessage(CHANNEL_NARRATIVE, "You don't have that much money.");
  8539. safe_delete(packet);
  8540. }
  8541. MMailWindowMutex.unlock();
  8542. }
  8543. else
  8544. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8545. return ret;
  8546. }
  8547. bool Client::RemoveMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  8548. bool ret = false;
  8549. if (GetMailTransaction()) {
  8550. MMailWindowMutex.lock();
  8551. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8552. if (packet) {
  8553. if (copper > 0) {
  8554. player->AddCoins(copper);
  8555. mail_window.coin_copper -= copper;
  8556. Message(CHANNEL_NARRATIVE, "You remove %u copper from the mail window.", copper);
  8557. ret = true;
  8558. }
  8559. else if (silver > 0) {
  8560. player->AddCoins(silver * 100);
  8561. mail_window.coin_silver -= silver;
  8562. Message(CHANNEL_NARRATIVE, "You remove %u silver from the mail window.", silver);
  8563. ret = true;
  8564. }
  8565. else if (gold > 0) {
  8566. player->AddCoins(gold * 10000);
  8567. mail_window.coin_gold -= gold;
  8568. Message(CHANNEL_NARRATIVE, "You remove %u gold from the mail window.", gold);
  8569. ret = true;
  8570. }
  8571. else if (plat > 0) {
  8572. player->AddCoins(plat * 1000000);
  8573. mail_window.coin_plat -= plat;
  8574. Message(CHANNEL_NARRATIVE, "You remove %u platinum from the mail window.", plat);
  8575. ret = true;
  8576. }
  8577. if (ret) {
  8578. packet->setDataByName("coin_copper", mail_window.coin_copper);
  8579. packet->setDataByName("coin_silver", mail_window.coin_silver);
  8580. packet->setDataByName("coin_gold", mail_window.coin_gold);
  8581. packet->setDataByName("coin_plat", mail_window.coin_plat);
  8582. packet->setDataByName("stack", 0);
  8583. packet->setDataByName("packettype", 0x2BFE);
  8584. packet->setDataByName("packetsubtype", 0xFF);
  8585. packet->setDataByName("unknown2", 0);
  8586. QueuePacket(packet->serialize());
  8587. }
  8588. safe_delete(packet);
  8589. }
  8590. MMailWindowMutex.unlock();
  8591. }
  8592. else
  8593. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8594. return ret;
  8595. }
  8596. void Client::TakeMailAttachments(int32 mail_id) {
  8597. if (GetMailTransaction()) {
  8598. Mail* mail = player->GetMail(mail_id);
  8599. if (mail) {
  8600. int64 amount = 0;
  8601. if (mail->coin_copper > 0) {
  8602. amount += mail->coin_copper;
  8603. mail->coin_copper = 0;
  8604. }
  8605. if (mail->coin_silver > 0) {
  8606. amount += mail->coin_silver * 100;
  8607. mail->coin_silver = 0;
  8608. }
  8609. if (mail->coin_gold > 0) {
  8610. amount += mail->coin_gold * 10000;
  8611. mail->coin_gold = 0;
  8612. }
  8613. if (mail->coin_plat > 0) {
  8614. amount += mail->coin_plat * 1000000;
  8615. mail->coin_plat = 0;
  8616. }
  8617. if (mail->char_item_id > 0) {
  8618. AddItem(mail->char_item_id, mail->stack);
  8619. mail->char_item_id = 0;
  8620. mail->stack = 0;
  8621. }
  8622. /* 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
  8623. the mail the player is getting attachments from. There is an opcode OP_MailRemoveAttachFromMailMsg with opcode 328 but i can't
  8624. find it in any packet logs.*/
  8625. /*PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8626. if (packet) {
  8627. packet->setDataByName("unknown", 0x03);
  8628. packet->setDataByName("coin_copper", mail->coin_copper);
  8629. packet->setDataByName("coin_silver", mail->coin_silver);
  8630. packet->setDataByName("coin_gold", mail->coin_gold);
  8631. packet->setDataByName("coin_plat", mail->coin_plat);
  8632. packet->setDataByName("stack", 0);
  8633. packet->setDataByName("packettype", 0x2BFE);
  8634. packet->setDataByName("packetsubtype", 0xFF);
  8635. packet->setDataByName("unknown2", 0);
  8636. packet->setDataByName("unknown3", 0x00000001);//0x00000016
  8637. DumpPacket(packet->serialize());
  8638. QueuePacket(packet->serialize());
  8639. safe_delete(packet);
  8640. }*/
  8641. database.SavePlayerMail(mail);
  8642. if (amount > 0)
  8643. player->AddCoins(amount);
  8644. SendMailList();
  8645. }
  8646. }
  8647. else
  8648. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8649. }
  8650. void Client::ResetSendMail(bool cancel, bool needslock) {
  8651. if(cancel && mail_transaction)
  8652. SimpleMessage(CHANNEL_NARRATIVE, "You cancel sending a letter.");
  8653. if(needslock)
  8654. MMailWindowMutex.lock();
  8655. if(cancel)
  8656. player->AddCoins(mail_window.coin_copper + (mail_window.coin_silver * 100) + (mail_window.coin_gold * 10000) + (mail_window.coin_plat * 1000000));
  8657. if(!cancel)
  8658. mail_transaction = 0;
  8659. mail_window.coin_copper = 0;
  8660. mail_window.coin_silver = 0;
  8661. mail_window.coin_gold = 0;
  8662. mail_window.coin_plat = 0;
  8663. mail_window.char_item_id = 0;
  8664. mail_window.stack = 0;
  8665. if(mail_window.item){
  8666. if(cancel)
  8667. AddItem(mail_window.item);
  8668. else
  8669. safe_delete(mail_window.item);
  8670. }
  8671. mail_window.item = nullptr;
  8672. if(needslock)
  8673. MMailWindowMutex.unlock();
  8674. }
  8675. bool Client::GateAllowed() {
  8676. ZoneServer* zone = GetCurrentZone();
  8677. if (zone){
  8678. bool cangate = zone->GetCanGate();
  8679. return cangate;
  8680. }
  8681. return false;
  8682. }
  8683. bool Client::BindAllowed() {
  8684. ZoneServer* zone = GetCurrentZone();
  8685. if (zone){
  8686. bool canbind = zone->GetCanBind();
  8687. return canbind;
  8688. }
  8689. return false;
  8690. }
  8691. bool Client::Bind() {
  8692. int canbind = BindAllowed();
  8693. if(canbind == 0) {
  8694. Message(CHANNEL_MERCHANT, "You cannot bind at this location.");
  8695. return false;
  8696. }
  8697. player->GetPlayerInfo()->SetBindZone(GetCurrentZone()->GetZoneID());
  8698. player->GetPlayerInfo()->SetBindX(player->GetX());
  8699. player->GetPlayerInfo()->SetBindY(player->GetY());
  8700. player->GetPlayerInfo()->SetBindZ(player->GetZ());
  8701. player->GetPlayerInfo()->SetBindHeading(player->GetHeading());
  8702. Message(CHANNEL_MERCHANT, "Your spirit has been bound to this location.");
  8703. return true;
  8704. }
  8705. bool Client::Gate(bool is_spell) {
  8706. if (player->GetPlayerInfo()->GetBindZoneID() == 0) {
  8707. SimpleMessage(CHANNEL_MERCHANT, "You can not cast recall spells. You have no bind location set.");
  8708. return false;
  8709. }
  8710. ZoneServer* zone = zone_list.Get(player->GetPlayerInfo()->GetBindZoneID());
  8711. if (zone) {
  8712. int cangate = GateAllowed();
  8713. if(cangate == 0) {
  8714. SimpleMessage(CHANNEL_MERCHANT, "You can not cast recall spells in this zone.");
  8715. return false;
  8716. }
  8717. player->SetX(player->GetPlayerInfo()->GetBindZoneX());
  8718. player->SetY(player->GetPlayerInfo()->GetBindZoneY());
  8719. player->SetZ(player->GetPlayerInfo()->GetBindZoneZ());
  8720. player->SetHeading(player->GetPlayerInfo()->GetBindZoneHeading());
  8721. Zone(zone, false, is_spell);
  8722. return true;
  8723. }
  8724. return false;
  8725. }
  8726. void Client::ProcessTeleport(Spawn* spawn, vector<TransportDestination*>* destinations, int32 transport_id, bool is_spell) {
  8727. if (!destinations || !spawn) {
  8728. return;
  8729. }
  8730. bool has_map = false;
  8731. if (transport_id > 0)
  8732. has_map = GetCurrentZone()->TransportHasMap(transport_id);
  8733. transport_spawn = spawn;
  8734. vector<TransportDestination*> transport_list;
  8735. vector<TransportDestination*>::iterator itr;
  8736. TransportDestination* destination = 0;
  8737. for (itr = destinations->begin(); itr != destinations->end(); itr++) {
  8738. destination = *itr;
  8739. 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)))
  8740. transport_list.push_back(destination);
  8741. }
  8742. if (transport_list.size() == 0 && destination) {
  8743. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  8744. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  8745. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  8746. else
  8747. {
  8748. EQ2Packet* app = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  8749. if (app)
  8750. QueuePacket(app);
  8751. }
  8752. }
  8753. else {
  8754. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  8755. // determine if this is an instanced zone that already exists
  8756. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(destination->destination_zone_id);
  8757. if (instance_zone || new_zone) {
  8758. GetPlayer()->SetX(destination->destination_x);
  8759. GetPlayer()->SetY(destination->destination_y);
  8760. GetPlayer()->SetZ(destination->destination_z);
  8761. GetPlayer()->SetHeading(destination->destination_heading);
  8762. if (instance_zone)
  8763. Zone(instance_zone->GetInstanceID(), false, true, is_spell);
  8764. else
  8765. Zone(new_zone, false, is_spell);
  8766. }
  8767. }
  8768. if (destination->message.length() > 0)
  8769. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  8770. }
  8771. else if (transport_list.size() > 0) {
  8772. if (!spawn->IsSoundsDisabled())
  8773. PlaySound("mariner_bell");
  8774. PacketStruct* packet = configReader.getStruct("WS_TeleportList", GetVersion());
  8775. if (packet) {
  8776. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  8777. // Put all the destinations the player can go in a new vector
  8778. vector<TransportDestination*> destinations;
  8779. for (int32 i = 0; i < transport_list.size(); i++) {
  8780. destination = transport_list.at(i);
  8781. // Check min level
  8782. if (destination->min_level > 0 && GetPlayer()->GetLevel() < destination->min_level)
  8783. continue;
  8784. // Check max level
  8785. if (destination->max_level > 0 && GetPlayer()->GetLevel() > destination->max_level)
  8786. continue;
  8787. // Check quest complete
  8788. if (destination->req_quest_complete > 0 && GetPlayer()->HasQuestBeenCompleted(destination->req_quest_complete) == 0)
  8789. continue;
  8790. // Check req quest and step
  8791. if (destination->req_quest > 0 && destination->req_quest_step > 0 && GetPlayer()->GetQuestStep(destination->req_quest) != destination->req_quest_step)
  8792. continue;
  8793. // 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
  8794. if (has_map && (destination->destination_zone_id == GetCurrentZone()->GetZoneID() && GetPlayer()->GetDistance(destination->destination_x, destination->destination_y, destination->destination_z) < 20)) {
  8795. packet->setDataByName("current_zone", destination->display_name.c_str());
  8796. packet->setDataByName("current_map_x", destination->map_x);
  8797. packet->setDataByName("current_map_y", destination->map_y);
  8798. }
  8799. else {
  8800. destinations.push_back(destination);
  8801. }
  8802. }
  8803. // Use the new vector to create the packet
  8804. destination = 0;
  8805. packet->setArrayLengthByName("num_destinations", destinations.size());
  8806. for (int32 i = 0; i < destinations.size(); i++) {
  8807. destination = destinations.at(i);
  8808. packet->setArrayDataByName("unique_id", destination->unique_id, i);
  8809. packet->setArrayDataByName("display_name", destination->display_name.c_str(), i);
  8810. packet->setArrayDataByName("zone_name", destination->display_name.c_str(), i);
  8811. packet->setArrayDataByName("zone_file_name", destination->display_name.c_str(), i);
  8812. packet->setArrayDataByName("cost", destination->cost, i);
  8813. if (has_map) {
  8814. packet->setArrayDataByName("map_x", destination->map_x, i);
  8815. packet->setArrayDataByName("map_y", destination->map_y, i);
  8816. }
  8817. }
  8818. if (has_map)
  8819. packet->setDataByName("map_name", GetCurrentZone()->GetTransportMap(transport_id).c_str());
  8820. EQ2Packet* app = packet->serialize();
  8821. //DumpPacket(app);
  8822. if (destinations.size() > 0)
  8823. QueuePacket(app);
  8824. safe_delete(packet);
  8825. }
  8826. }
  8827. }
  8828. void Client::ProcessTeleportLocation(EQApplicationPacket* app) {
  8829. PacketStruct* packet = configReader.getStruct("WS_TeleportDestination", GetVersion());
  8830. if (packet) {
  8831. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  8832. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(packet->getType_int32_ByName("spawn_id"));
  8833. int32 unique_id = packet->getType_int32_ByName("unique_id");
  8834. string zone_name = packet->getType_EQ2_16BitString_ByName("zone_name").data;
  8835. int32 cost = packet->getType_int32_ByName("cost");
  8836. vector<TransportDestination*> destinations;
  8837. TransportDestination* destination = 0;
  8838. if (this->GetTemporaryTransportID() || (spawn && spawn == transport_spawn && spawn->GetTransporterID()))
  8839. GetCurrentZone()->GetTransporters(&destinations, this, this->GetTemporaryTransportID() ? this->GetTemporaryTransportID() : spawn->GetTransporterID());
  8840. vector<TransportDestination*>::iterator itr;
  8841. for (itr = destinations.begin(); itr != destinations.end(); itr++) {
  8842. if ((*itr)->unique_id == unique_id && (*itr)->display_name == zone_name && (*itr)->cost == cost) {
  8843. destination = *itr;
  8844. break;
  8845. }
  8846. }
  8847. SetTemporaryTransportID(0);
  8848. if (!destination)
  8849. SimpleMessage(CHANNEL_COLOR_RED, "Error processing transport.");
  8850. else {
  8851. if (cost == 0 || player->RemoveCoins(cost)) {
  8852. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  8853. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  8854. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  8855. else
  8856. {
  8857. EQ2Packet* outapp = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  8858. if (outapp)
  8859. QueuePacket(outapp);
  8860. }
  8861. }
  8862. else {
  8863. GetPlayer()->SetX(destination->destination_x);
  8864. GetPlayer()->SetY(destination->destination_y);
  8865. GetPlayer()->SetZ(destination->destination_z);
  8866. GetPlayer()->SetHeading(destination->destination_heading);
  8867. // Test if where we're going is an Instanced zone
  8868. if (!TryZoneInstance(destination->destination_zone_id, false)) {
  8869. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Attempting to zone normally");
  8870. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  8871. Zone(new_zone, false);
  8872. }
  8873. }
  8874. if (destination->message.length() > 0)
  8875. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  8876. }
  8877. else
  8878. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough money to use this transport.");
  8879. }
  8880. }
  8881. safe_delete(packet);
  8882. }
  8883. }
  8884. void Client::SendNewSpells(int8 class_id) {
  8885. if (class_id > 0) {
  8886. vector<Spell*>* spells = master_spell_list.GetSpellListByAdventureClass(class_id, player->GetLevel(), 1);
  8887. AddSendNewSpells(spells);
  8888. safe_delete(spells);
  8889. }
  8890. }
  8891. void Client::SendNewTSSpells(int8 class_id) {
  8892. if (class_id > 0) {
  8893. vector<Spell*>* spells = master_spell_list.GetSpellListByTradeskillClass(class_id, player->GetLevel(), 1);
  8894. AddSendNewSpells(spells);
  8895. safe_delete(spells);
  8896. }
  8897. }
  8898. void Client::AddSendNewSpells(vector<Spell*>* spells) {
  8899. Spell* spell = 0;
  8900. bool send_updates = false;
  8901. vector<Spell*>::iterator itr;
  8902. for (itr = spells->begin(); itr != spells->end(); itr++) {
  8903. spell = *itr;
  8904. if (spell && !player->HasSpell(spell->GetSpellID(), spell->GetSpellTier(), true) && spell->GetSpellData()->lua_script.length() > 0) {
  8905. send_updates = true;
  8906. SendSpellUpdate(spell);
  8907. player->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), player->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  8908. player->UnlockSpell(spell);
  8909. }
  8910. }
  8911. if (send_updates) {
  8912. EQ2Packet* outapp = player->GetSpellBookUpdatePacket(GetVersion());
  8913. if (outapp)
  8914. QueuePacket(outapp);
  8915. }
  8916. }
  8917. void Client::SetItemSearch(vector<Item*>* items) {
  8918. if (items) {
  8919. safe_delete(search_items);
  8920. search_items = items;
  8921. }
  8922. }
  8923. vector<Item*>* Client::GetSearchItems() {
  8924. return search_items;
  8925. }
  8926. void Client::SearchStore(int32 page) {
  8927. if (search_items) {
  8928. PacketStruct* packet = configReader.getStruct("WS_BrokerItems", GetVersion());
  8929. if (packet) {
  8930. int32 x = page * 8;
  8931. if (search_items->size() > 8) {
  8932. if ((search_items->size() - x) > 8)
  8933. packet->setArrayLengthByName("num_items", 8);
  8934. else
  8935. packet->setArrayLengthByName("num_items", search_items->size() - x);
  8936. }
  8937. else
  8938. packet->setArrayLengthByName("num_items", search_items->size());
  8939. if (search_items->size() > 0) {
  8940. packet->setArrayLengthByName("num_sellers", 1);
  8941. packet->setArrayDataByName("seller_seller_id", 1);
  8942. packet->setDataByName("per_page", 8);
  8943. packet->setDataByName("num_pages", search_items->size() / 8 + 1);
  8944. packet->setDataByName("page", page);
  8945. Item* item = 0;
  8946. int32 limit = search_items->size() > 8 ? 8 : search_items->size();
  8947. for (int32 i = 0; i < limit; i++, x++) {
  8948. if (x >= search_items->size())
  8949. break;
  8950. item = search_items->at(x);
  8951. std::string teststr("test ");
  8952. teststr.append(std::to_string(i));
  8953. packet->setArrayDataByName("string_one", teststr.c_str(), i);
  8954. packet->setArrayDataByName("string_two", "testtwo", i);
  8955. packet->setArrayDataByName("seller_name", "EQ2EMuDev", i);
  8956. packet->setArrayDataByName("item_id", item->details.item_id, i);
  8957. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  8958. packet->setArrayDataByName("icon", item->details.icon, i);
  8959. //packet->setArrayDataByName("unknown2b", i, i);
  8960. packet->setArrayDataByName("item_seller_id", 1, i);
  8961. if (item->stack_count == 0)
  8962. packet->setArrayDataByName("quantity", 1, i);
  8963. else
  8964. packet->setArrayDataByName("quantity", item->stack_count, i);
  8965. packet->setArrayDataByName("stack_size", item->stack_count, i);
  8966. packet->setArrayDataByName("sell_price", item->sell_price, i);
  8967. std::string tmpStr("");
  8968. tmpStr.append(item->name.c_str());
  8969. tmpStr.append(" (");
  8970. tmpStr.append(std::to_string(item->details.item_id));
  8971. tmpStr.append(")");
  8972. packet->setArrayDataByName("item_name", tmpStr.c_str(), i);
  8973. packet->setArrayDataByName("req_level", item->generic_info.adventure_default_level, i);
  8974. //QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  8975. }
  8976. }
  8977. EQ2Packet* outapp = packet->serialize();
  8978. DumpPacket(outapp);
  8979. QueuePacket(outapp);
  8980. safe_delete(packet);
  8981. }
  8982. }
  8983. }
  8984. void Client::SetReadyForUpdates() {
  8985. if (!ready_for_updates) {
  8986. database.loadCharacterProperties(this);
  8987. SendDefaultGroupOptions();
  8988. }
  8989. ready_for_updates = true;
  8990. if(GetVersion() <= 561) {
  8991. SendRecipeList();
  8992. }
  8993. }
  8994. void Client::SetReadyForSpawns(bool val) {
  8995. ready_for_spawns = val;
  8996. if (GetPlayer()->GetActivityStatus() > 0) {
  8997. GetPlayer()->SetActivityStatus(0);
  8998. if (GetPlayer()->GetGroupMemberInfo()) {
  8999. world.GetGroupManager()->GroupMessage(GetPlayer()->GetGroupMemberInfo()->group_id, "%s has returned from Linkdead.", GetPlayer()->GetName());
  9000. }
  9001. }
  9002. GetPlayer()->SetActiveReward(false);
  9003. zone_list.CheckFriendZoned(this);
  9004. }
  9005. void Client::SendChatRelationship(int8 type, const char* name) {
  9006. if (!name) {
  9007. return;
  9008. }
  9009. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  9010. if (packet) {
  9011. packet->setDataByName("account_id", GetAccountID());
  9012. packet->setDataByName("type", type);
  9013. packet->setArrayLengthByName("num_names", 1);
  9014. packet->setArrayDataByName("name", name);
  9015. if (type == 0) {
  9016. Client* client = zone_list.GetClientByCharName(name);
  9017. if (client) {
  9018. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName());
  9019. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()));
  9020. }
  9021. }
  9022. QueuePacket(packet->serialize());
  9023. safe_delete(packet);
  9024. }
  9025. }
  9026. void Client::SendFriendList() {
  9027. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  9028. if (packet) {
  9029. packet->setDataByName("account_id", GetAccountID());
  9030. map<string, int8>::iterator itr;
  9031. map<string, int8>* friends = player->GetFriends();
  9032. if (friends && friends->size() > 0) {
  9033. Client* client = 0;
  9034. vector<string> names;
  9035. for (itr = friends->begin(); itr != friends->end(); itr++) {
  9036. if (itr->second == 2)
  9037. continue;
  9038. names.push_back(itr->first);
  9039. }
  9040. packet->setArrayLengthByName("num_names", names.size());
  9041. for (int32 i = 0; i < names.size(); i++) {
  9042. client = zone_list.GetClientByCharName(names[i]);
  9043. packet->setArrayDataByName("name", names[i].c_str(), i);
  9044. if (client) {
  9045. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName(), i);
  9046. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()), i);
  9047. }
  9048. }
  9049. }
  9050. QueuePacket(packet->serialize());
  9051. safe_delete(packet);
  9052. }
  9053. }
  9054. void Client::SendIgnoreList() {
  9055. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  9056. if (packet) {
  9057. packet->setDataByName("account_id", GetAccountID());
  9058. packet->setDataByName("type", 2);
  9059. map<string, int8>::iterator itr;
  9060. map<string, int8>* ignored = player->GetIgnoredPlayers();
  9061. if (ignored && ignored->size() > 0) {
  9062. vector<string> names;
  9063. for (itr = ignored->begin(); itr != ignored->end(); itr++) {
  9064. if (itr->second == 2)
  9065. continue;
  9066. names.push_back(itr->first);
  9067. }
  9068. packet->setArrayLengthByName("num_names", names.size());
  9069. for (int32 i = 0; i < names.size(); i++)
  9070. packet->setArrayDataByName("name", names[i].c_str(), i);
  9071. }
  9072. QueuePacket(packet->serialize());
  9073. safe_delete(packet);
  9074. }
  9075. }
  9076. void Client::AddWaypoint(string name, int8 type) {
  9077. waypoint_id++;
  9078. WaypointInfo info;
  9079. info.id = waypoint_id;
  9080. info.type = type;
  9081. waypoints[name] = info;
  9082. }
  9083. void Client::SendWaypoints() {
  9084. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  9085. if (packet) {
  9086. packet->setArrayLengthByName("num_updates", waypoints.size());
  9087. map<string, WaypointInfo>::iterator itr;
  9088. int16 i = 0;
  9089. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  9090. packet->setArrayDataByName("waypoint_name", itr->first.c_str(), i);
  9091. packet->setArrayDataByName("waypoint_category", itr->second.type, i);
  9092. packet->setArrayDataByName("spawn_id", itr->second.id, i);
  9093. i++;
  9094. }
  9095. packet->setDataByName("unknown", 0xFFFFFFFF);
  9096. QueuePacket(packet->serialize());
  9097. safe_delete(packet);
  9098. }
  9099. }
  9100. void Client::SelectWaypoint(int32 id) {
  9101. string found_name = "";
  9102. map<string, WaypointInfo>::iterator itr;
  9103. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  9104. if (itr->second.id == id) {
  9105. found_name = itr->first;
  9106. break;
  9107. }
  9108. }
  9109. if (found_name.length() > 0) {
  9110. Spawn* spawn = current_zone->FindSpawn(player, found_name.c_str());
  9111. ShowPathToTarget(spawn);
  9112. }
  9113. }
  9114. void Client::AddWaypoint(const char* waypoint_name, int8 waypoint_category, int32 spawn_id) {
  9115. if (waypoint_name) {
  9116. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  9117. if (packet) {
  9118. packet->setArrayLengthByName("num_updates", 1);
  9119. packet->setArrayDataByName("waypoint_name", waypoint_name, 0);
  9120. packet->setArrayDataByName("waypoint_category", waypoint_category, 0);
  9121. packet->setArrayDataByName("spawn_id", spawn_id, 0);
  9122. packet->setArrayDataByName("waypoint_category2", waypoint_category, 0);
  9123. packet->setArrayDataByName("spawn_id2", spawn_id, 0);
  9124. packet->setDataByName("unknown", 0xFFFFFFFF);
  9125. QueuePacket(packet->serialize());
  9126. safe_delete(packet);
  9127. }
  9128. }
  9129. }
  9130. void Client::ClearWaypoint() {
  9131. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  9132. if (packet) {
  9133. QueuePacket(packet->serialize());
  9134. safe_delete(packet);
  9135. }
  9136. }
  9137. bool Client::ShowPathToTarget(float x, float y, float z, float y_offset) {
  9138. if (current_zone->pathing) {
  9139. if (GetPlayer()->GetMap()) {
  9140. if (x < GetPlayer()->GetMap()->GetMinX() || x > GetPlayer()->GetMap()->GetMaxX())
  9141. return false;
  9142. if (z < GetPlayer()->GetMap()->GetMinZ() || z > GetPlayer()->GetMap()->GetMaxZ())
  9143. return false;
  9144. auto loc = glm::vec3(x, z, y);
  9145. float new_z = GetPlayer()->FindBestZ(loc, nullptr);
  9146. if (new_z != BEST_Z_INVALID) //this is actually y
  9147. y = new_z;
  9148. }
  9149. bool partial = false;
  9150. bool stuck = false;
  9151. PathfinderOptions opts;
  9152. opts.smooth_path = true;
  9153. opts.step_size = 100.0f;//RuleR(Pathing, NavmeshStepSize);
  9154. opts.offset = y_offset + 1.0f;
  9155. opts.flags = PathingNotDisabled ^ PathingZoneLine;
  9156. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  9157. if (packet) {
  9158. auto path = current_zone->pathing->FindPath(glm::vec3(player->GetX(), player->GetZ(), player->GetY()), glm::vec3(x, z, y), partial, stuck, opts);
  9159. packet->setArrayLengthByName("num_points", path.size());
  9160. int i = 0;
  9161. for (auto& node : path)
  9162. {
  9163. packet->setArrayDataByName("x", node.pos.x, i);
  9164. packet->setArrayDataByName("y", node.pos.z, i);
  9165. packet->setArrayDataByName("z", node.pos.y, i);
  9166. packet->setDataByName("waypoint_x", x);
  9167. packet->setDataByName("waypoint_y", y);
  9168. packet->setDataByName("waypoint_z", z);
  9169. i++;
  9170. }
  9171. if (i > 0)
  9172. QueuePacket(packet->serialize());
  9173. safe_delete(packet);
  9174. return (i > 0);
  9175. }
  9176. }
  9177. return false;
  9178. }
  9179. bool Client::ShowPathToTarget(Spawn* spawn) {
  9180. if (spawn) {
  9181. return ShowPathToTarget(spawn->GetX(), spawn->GetY(), spawn->GetZ(), spawn->GetYOffset());
  9182. }
  9183. return false;
  9184. }
  9185. void Client::BeginWaypoint(const char* waypoint_name, float x, float y, float z) {
  9186. if (waypoint_name) {
  9187. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  9188. if (packet) {
  9189. packet->setArrayLengthByName("num_points", 1);
  9190. packet->setArrayDataByName("x", x, 0);
  9191. packet->setArrayDataByName("y", y, 0);
  9192. packet->setArrayDataByName("z", z, 0);
  9193. packet->setDataByName("waypoint_x", x);
  9194. packet->setDataByName("waypoint_y", y);
  9195. packet->setDataByName("waypoint_z", z);
  9196. packet->setDataByName("waypoint_name", waypoint_name);
  9197. packet->setDataByName("unknown", 0);
  9198. QueuePacket(packet->serialize());
  9199. safe_delete(packet);
  9200. }
  9201. }
  9202. }
  9203. void Client::InspectPlayer(Player* player_to_inspect) {
  9204. int source_pvp_alignment = GetPlayer()->GetPVPAlignment();
  9205. int target_pvp_alignment = player_to_inspect->GetPVPAlignment();
  9206. bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
  9207. if(pvp_allowed == true){
  9208. if(source_pvp_alignment != target_pvp_alignment){
  9209. Message(CHANNEL_COLOR_RED, "You can not inspect players of different alignments.");
  9210. return;
  9211. }
  9212. }
  9213. if (player_to_inspect && player_to_inspect->GetClient()) {
  9214. PacketStruct* packet = configReader.getStruct("WS_InspectPlayer", GetVersion());
  9215. if (packet) {
  9216. packet->setDataByName("unknown", 0);
  9217. packet->setSmallStringByName("name", player_to_inspect->GetName());
  9218. packet->setDataByName("race", player_to_inspect->GetRace());
  9219. packet->setDataByName("gender", player_to_inspect->GetGender());
  9220. packet->setDataByName("adventure_level", player_to_inspect->GetLevel());
  9221. int16 effective_level = player_to_inspect->GetInfoStruct()->get_effective_level() != 0 ? player_to_inspect->GetInfoStruct()->get_effective_level() : player_to_inspect->GetLevel();
  9222. packet->setDataByName("adventure_level_effective", effective_level);
  9223. packet->setDataByName("adventure_class", player_to_inspect->GetAdventureClass());
  9224. packet->setDataByName("tradeskill_level", player_to_inspect->GetTSLevel());
  9225. packet->setDataByName("tradeskill_class", player_to_inspect->GetTradeskillClass());
  9226. packet->setDataByName("health", player_to_inspect->GetHP());
  9227. packet->setDataByName("health_max", player_to_inspect->GetTotalHP());
  9228. packet->setDataByName("health_base", player_to_inspect->GetTotalHPBase());
  9229. packet->setDataByName("power", player_to_inspect->GetPower());
  9230. packet->setDataByName("power_max", player_to_inspect->GetTotalPower());
  9231. packet->setDataByName("power_base", player_to_inspect->GetTotalPowerBase());
  9232. packet->setDataByName("mitigation", player_to_inspect->GetInfoStruct()->get_cur_mitigation());
  9233. packet->setDataByName("unknown1", 0);
  9234. packet->setDataByName("avoidance", player_to_inspect->GetInfoStruct()->get_avoidance_display()*10.0f);
  9235. packet->setDataByName("unknown2", 0);
  9236. packet->setDataByName("mitigation_percentage", 0);
  9237. packet->setDataByName("strength", player_to_inspect->GetStr());
  9238. packet->setDataByName("strength_base", player_to_inspect->GetStrBase());
  9239. packet->setDataByName("stamina", player_to_inspect->GetSta());
  9240. packet->setDataByName("stamina_base", player_to_inspect->GetStaBase());
  9241. packet->setDataByName("agility", player_to_inspect->GetAgi());
  9242. packet->setDataByName("agility_base", player_to_inspect->GetAgiBase());
  9243. packet->setDataByName("wisdom", player_to_inspect->GetWis());
  9244. packet->setDataByName("wisdom_base", player_to_inspect->GetWisBase());
  9245. packet->setDataByName("intelligence", player_to_inspect->GetInt());
  9246. packet->setDataByName("intelligence_base", player_to_inspect->GetIntBase());
  9247. packet->setDataByName("unknown4", 0);
  9248. packet->setDataByName("unknown5", 0);
  9249. packet->setDataByName("unknown6", 0);
  9250. packet->setDataByName("unknown7", 0);
  9251. packet->setDataByName("unknown8", 0);
  9252. packet->setDataByName("unknown9", 0);
  9253. packet->setDataByName("unknown10", 0);
  9254. packet->setDataByName("unknown11", 0);
  9255. packet->setDataByName("unknown12", 0);
  9256. packet->setDataByName("heat_resist", player_to_inspect->GetHeatResistance());
  9257. packet->setDataByName("heat_resist_base", player_to_inspect->GetHeatResistanceBase());
  9258. packet->setDataByName("heat_resist_percentage", 0);
  9259. packet->setDataByName("cold_resist", player_to_inspect->GetColdResistance());
  9260. packet->setDataByName("cold_resist_base", player_to_inspect->GetColdResistanceBase());
  9261. packet->setDataByName("cold_resist_percentage", 0);
  9262. packet->setDataByName("magic_resist", player_to_inspect->GetMagicResistance());
  9263. packet->setDataByName("magic_resist_base", player_to_inspect->GetMagicResistanceBase());
  9264. packet->setDataByName("magic_resist_percentage", 0);
  9265. packet->setDataByName("mental_resist", player_to_inspect->GetMentalResistance());
  9266. packet->setDataByName("mental_resist_base", player_to_inspect->GetMentalResistanceBase());
  9267. packet->setDataByName("mental_resist_percentage", 0);
  9268. packet->setDataByName("divine_resist", player_to_inspect->GetDivineResistance());
  9269. packet->setDataByName("divine_resist_base", player_to_inspect->GetDivineResistanceBase());
  9270. packet->setDataByName("divine_resist_percentage", 0);
  9271. packet->setDataByName("disease_resist", player_to_inspect->GetDiseaseResistance());
  9272. packet->setDataByName("disease_resist_base", player_to_inspect->GetDiseaseResistanceBase());
  9273. packet->setDataByName("disease_resist_percentage", 0);
  9274. packet->setDataByName("poison_resist", player_to_inspect->GetPoisonResistance());
  9275. packet->setDataByName("poison_resist_base", player_to_inspect->GetPoisonResistanceBase());
  9276. packet->setDataByName("poison_resist_percentage", 0);
  9277. packet->setArrayLengthByName("num_chars", 0x01FF);
  9278. string biography = player_to_inspect->GetBiography();
  9279. for (size_t i = 0; i < biography.length(); i++)
  9280. packet->setArrayDataByName("biography_char", biography[i], i);
  9281. if(GetVersion() <= 373) {
  9282. for(int32 s=0;s<20;s++) {
  9283. int32 slot = s;
  9284. char item_slot_name[64], item_slot_name_appearance[64];
  9285. _snprintf(item_slot_name,64,"slot_%u",slot);
  9286. Item* pw = player_to_inspect->GetEquipmentList()->GetItem(GetPlayer()->ConvertSlotFromClient(s, GetVersion()));
  9287. packet->setItemByName(item_slot_name, pw, this->GetPlayer(), 0, 7, true, true, true);
  9288. }
  9289. }
  9290. else if(GetVersion() <= 561) {
  9291. for(int32 s=0;s<22;s++) {
  9292. int32 slot = s;
  9293. char item_slot_name[64], item_slot_name_appearance[64];
  9294. _snprintf(item_slot_name,64,"slot_%u",slot);
  9295. Item* pw = player_to_inspect->GetEquipmentList()->GetItem(GetPlayer()->ConvertSlotFromClient(s, GetVersion()));
  9296. packet->setItemByName(item_slot_name, pw, this->GetPlayer(), 0, 5, true, true);
  9297. }
  9298. }
  9299. else {
  9300. for(int32 s=0;s<NUM_SLOTS;s++) {
  9301. int32 slot = s*2;
  9302. char item_slot_name[64], item_slot_name_appearance[64];
  9303. _snprintf(item_slot_name,64,"slot_%u",slot);
  9304. int32 slot_appearance = (s*2)+1;
  9305. _snprintf(item_slot_name_appearance,64,"slot_%u",slot_appearance);
  9306. Item* pw = player_to_inspect->GetEquipmentList()->GetItem(GetPlayer()->ConvertSlotFromClient(s, player_to_inspect->GetClient()->GetVersion()));
  9307. packet->setItemByName(item_slot_name, pw, this->GetPlayer(), 0, 13, false, true);
  9308. if(s <= EQ2_FEET_SLOT || s == EQ2_RANGE_SLOT || s == EQ2_CLOAK_SLOT) {
  9309. pw = player_to_inspect->GetAppearanceEquipmentList()->GetItem(s);
  9310. packet->setItemByName(item_slot_name_appearance, pw, this->GetPlayer(), 0, 13, false, true);
  9311. }
  9312. else {
  9313. packet->setItemByName(item_slot_name_appearance, nullptr, this->GetPlayer(), 0, 13, false, true);
  9314. }
  9315. }
  9316. }
  9317. QueuePacket(packet->serialize());
  9318. safe_delete(packet);
  9319. }
  9320. }
  9321. }
  9322. void Client::SetPendingGuildInvite(Guild* guild, Player* invited_by) {
  9323. pending_guild_invite.guild = guild;
  9324. pending_guild_invite.invited_by = invited_by;
  9325. }
  9326. void Client::ShowClaimWindow() {
  9327. PacketStruct* packet = configReader.getStruct("WS_PromoFlagsDetails", GetVersion());
  9328. if (packet) {
  9329. int16 loaded = database.CountCharClaimItems(GetCharacterID());
  9330. vector<ClaimItems> claim = database.LoadCharacterClaimItems(GetCharacterID());
  9331. int32 account_age = database.GetAccountAge(GetAccountID());
  9332. //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.
  9333. if (loaded == 0 || claim.empty()) {
  9334. Message(CHANNEL_COLOR_RED, "You have nothing to claim.");
  9335. return;
  9336. }
  9337. packet->setArrayLengthByName("num_claim_items", loaded);
  9338. int j = 0; //use this to track skipped vet items.
  9339. for (int i = 0; i < claim.size(); i++)
  9340. {
  9341. if (j == claim.size()) {
  9342. Message(CHANNEL_COLOR_RED, "You have nothing to claim.");
  9343. return;
  9344. }
  9345. Item* item = master_item_list.GetItem(claim[i].item_id);
  9346. int16 claimed = 0;
  9347. if (claim[i].curr_claim < claim[i].max_claim) {
  9348. claimed = claim[i].max_claim - claim[i].curr_claim;
  9349. }
  9350. else {
  9351. claimed = 0;
  9352. }
  9353. //dont display vet rewards until they reach the age required
  9354. if (account_age < claim[i].vet_reward_time) {
  9355. j++;
  9356. continue;
  9357. }
  9358. packet->setArrayDataByName("id", i, i);
  9359. packet->setArrayDataByName("not_yet_claimed", 1, i);
  9360. packet->setArrayDataByName("num_remaining", claim[i].curr_claim, i);
  9361. packet->setArrayDataByName("one_per_character", claim[i].one_per_char, i);
  9362. packet->setArrayDataByName("claimed_on_this_char", 0, i);
  9363. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  9364. packet->setArrayDataByName("text", "If you ever see this text, let a developer know!", i); //I've not seen this!
  9365. //packet->setArrayDataByName("category", "Scott's Shit", i); //devn00b: not using so commenting out, leaving in case we ever do implement categories.
  9366. packet->setArrayDataByName("icon", item->details.icon, i);
  9367. packet->setArrayDataByName("item_id", item->details.item_id, i);
  9368. j++;
  9369. }
  9370. }
  9371. packet->setDataByName("unknown3", 1);
  9372. QueuePacket(packet->serialize());
  9373. safe_delete(packet);
  9374. }
  9375. void Client::ShowGuildSearchWindow() {
  9376. PacketStruct* packet = configReader.getStruct("WS_GuildRecruiting", GetVersion());
  9377. if (packet) {
  9378. MutexMap<int32, Guild*>* guilds = guild_list.GetGuilds();
  9379. MutexMap<int32, Guild*>::iterator itr = guilds->begin();
  9380. packet->setArrayLengthByName("num_guilds", guilds->size());
  9381. int32 i = 0;
  9382. while (itr.Next()) {
  9383. Guild* guild = itr.second;
  9384. packet->setArrayDataByName("guild_id", guild->GetID(), i);
  9385. packet->setArrayDataByName("guild_name", guild->GetName(), i);
  9386. packet->setArrayDataByName("recruiting_short_description", guild->GetRecruitingShortDesc().c_str(), i);
  9387. packet->setArrayDataByName("descriptive_tag1", guild->GetRecruitingDescTag(0), i);
  9388. packet->setArrayDataByName("descriptive_tag2", guild->GetRecruitingDescTag(1), i);
  9389. packet->setArrayDataByName("descriptive_tag3", guild->GetRecruitingDescTag(2), i);
  9390. packet->setArrayDataByName("descriptive_tag4", guild->GetRecruitingDescTag(3), i);
  9391. packet->setArrayDataByName("playstyle", guild->GetRecruitingPlayStyle(), i);
  9392. packet->setArrayDataByName("looking_for", guild->GetRecruitingLookingForPacketValue(), i); //tradeskillers, fighters, new
  9393. packet->setArrayDataByName("unknown7", 0x02, i);
  9394. packet->setArrayDataByName("min_level", guild->GetRecruitingMinLevel(), i);
  9395. i++;
  9396. }
  9397. QueuePacket(packet->serialize());
  9398. safe_delete(packet);
  9399. }
  9400. }
  9401. void Client::ShowDressingRoom(Item* item, sint32 crc) {
  9402. PacketStruct* packet;
  9403. vector<int8>* slot_data;
  9404. vector<int8>::iterator itr;
  9405. int32 slots = 0;
  9406. assert(item);
  9407. if (!(packet = configReader.getStruct("WS_DressingRoom", GetVersion()))) {
  9408. return;
  9409. }
  9410. slot_data = &item->slot_data;
  9411. for (itr = slot_data->begin(); itr != slot_data->end(); itr++) {
  9412. if (version >= 1188)
  9413. slots = *itr;
  9414. else
  9415. slots += (int8)pow(2.0, *itr);
  9416. }
  9417. packet->setDataByName("slot", slots);
  9418. packet->setDataByName("appearance_id", item->generic_info.appearance_id);
  9419. if (slots == 2) {
  9420. packet->setDataByName("rgb", item->generic_info.appearance_red, 2);
  9421. packet->setDataByName("rgb", item->generic_info.appearance_blue, 0);
  9422. }
  9423. else {
  9424. packet->setDataByName("rgb", item->generic_info.appearance_red, 0);
  9425. packet->setDataByName("rgb", item->generic_info.appearance_blue, 2);
  9426. }
  9427. packet->setDataByName("rgb", item->generic_info.appearance_green, 1);
  9428. if (slots == 4) {
  9429. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 2);
  9430. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  9431. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 0);
  9432. }
  9433. else if (slots == 7) {
  9434. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 1);
  9435. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 0);
  9436. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  9437. }
  9438. else {
  9439. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 0);
  9440. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  9441. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  9442. }
  9443. packet->setDataByName("icon", item->details.icon);
  9444. packet->setDataByName("item_id", item->details.item_id);
  9445. packet->setDataByName("item_crc", crc);
  9446. packet->setDataByName("unknown2", 0xFFFFFFFF);
  9447. packet->setDataByName("unknown4", 0xFFFFFFFF);
  9448. packet->setDataByName("unknown5", 0xFF, 9);
  9449. packet->setDataByName("unknown5", 0xFF, 10);
  9450. QueuePacket(packet->serialize());
  9451. safe_delete(packet);
  9452. }
  9453. void Client::SendCollectionList() {
  9454. map<int32, Collection*>* collections = player->GetCollectionList()->GetCollections();
  9455. map<int32, Collection*>::iterator itr;
  9456. vector<struct CollectionItem*>* collection_items;
  9457. Collection* collection;
  9458. struct CollectionItem* collection_item;
  9459. PacketStruct* packet = 0;
  9460. int16 i = 0, j;
  9461. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version)))
  9462. return;
  9463. packet->setArrayLengthByName("num_collections", collections->size());
  9464. for (itr = collections->begin(); itr != collections->end(); itr++) {
  9465. collection = itr->second;
  9466. collection_items = collection->GetCollectionItems();
  9467. packet->setArrayDataByName("unknown", 1, i);
  9468. packet->setArrayDataByName("collection_name", collection->GetName(), i);
  9469. packet->setArrayDataByName("collection_category", collection->GetCategory(), i);
  9470. packet->setArrayDataByName("completed", collection->GetCompleted(), i);
  9471. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  9472. packet->setArrayDataByName("level", collection->GetLevel(), i);
  9473. packet->setArrayDataByName("ready_to_turn_in", collection->GetIsReadyToTurnIn(), i);
  9474. packet->setSubArrayLengthByName("num_items", collection_items->size(), i);
  9475. for (j = 0; j < collection_items->size(); j++) {
  9476. collection_item = collection_items->at(j);
  9477. Item* item = master_item_list.GetItem(collection_item->item);
  9478. if (item) {
  9479. packet->setSubArrayDataByName("item_icon", item->details.icon, i, j);
  9480. if (version < 955)
  9481. packet->setSubArrayDataByName("item_name", item->name.c_str(), i, j);
  9482. else
  9483. packet->setSubArrayDataByName("item_id", item->details.item_id, i, j);
  9484. }
  9485. packet->setSubArrayDataByName("item_flag", collection_item->found, i, j);
  9486. }
  9487. i++;
  9488. }
  9489. packet->setDataByName("new_collection_flag", 1);
  9490. QueuePacket(packet->serialize());
  9491. safe_delete(packet);
  9492. }
  9493. bool Client::SendCollectionsForItem(Item* item) {
  9494. map<int32, Collection*> collections_to_send;
  9495. map<int32, Collection*>* collections;
  9496. map<int32, Collection*>::iterator itr;
  9497. vector<struct CollectionItem*>* collection_items;
  9498. Collection* collection;
  9499. struct CollectionItem* collection_item;
  9500. PacketStruct* packet;
  9501. int16 i;
  9502. assert(item);
  9503. /* get any collections required by this item that the player already has */
  9504. collections = player->GetCollectionList()->GetCollections();
  9505. for (itr = collections->begin(); itr != collections->end(); itr++) {
  9506. collection = itr->second;
  9507. if (!collection->GetCompleted() && !collection->GetIsReadyToTurnIn() && collection->NeedsItem(item)) {
  9508. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from player list %u\n", collection->GetID());
  9509. collections_to_send[collection->GetID()] = collection;
  9510. }
  9511. }
  9512. /* get any collections required by this item that the player does not have and send it to the client */
  9513. collections = master_collection_list.GetCollections();
  9514. for (itr = collections->begin(); itr != collections->end(); itr++) {
  9515. collection = itr->second;
  9516. if (collection->NeedsItem(item) && !player->GetCollectionList()->GetCollection(collection->GetID())) {
  9517. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version))) {
  9518. return false;
  9519. }
  9520. packet->setArrayLengthByName("num_collections", 1);
  9521. packet->setArrayDataByName("unknown", 1, 0);
  9522. packet->setArrayDataByName("collection_name", collection->GetName(), 0);
  9523. packet->setArrayDataByName("collection_category", collection->GetCategory(), 0);
  9524. packet->setArrayDataByName("completed", 0, 0);
  9525. packet->setArrayDataByName("collection_id", collection->GetID(), 0);
  9526. packet->setArrayDataByName("level", collection->GetLevel(), 0);
  9527. packet->setArrayDataByName("ready_to_turn_in", 0, 0);
  9528. packet->setArrayDataByName("unknown3", 0x28, 0);
  9529. collection_items = collection->GetCollectionItems();
  9530. packet->setSubArrayLengthByName("num_items", collection_items->size(), 0);
  9531. for (i = 0; i < collection_items->size(); i++) {
  9532. collection_item = collection_items->at(i);
  9533. Item* item2 = master_item_list.GetItem(collection_item->item);
  9534. if (item2) {
  9535. packet->setSubArrayDataByName("item_icon", item2->details.icon, 0, i);
  9536. if (version < 955)
  9537. packet->setSubArrayDataByName("item_name", item2->name.c_str(), 0, i);
  9538. else
  9539. packet->setSubArrayDataByName("item_id", item2->details.item_id, 0, i);
  9540. packet->setSubArrayDataByName("item_flag", collection_item->found, 0, i);
  9541. }
  9542. }
  9543. packet->setDataByName("new_collection_flag", 0);
  9544. QueuePacket(packet->serialize());
  9545. safe_delete(packet);
  9546. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from master list %u\n", collection->GetID());
  9547. collections_to_send[collection->GetID()] = collection;
  9548. }
  9549. }
  9550. /* send the client a list of collections that should be filtered for this item */
  9551. if (collections_to_send.size() > 0) {
  9552. if (!(packet = configReader.getStruct("WS_CollectionFilter", version))) {
  9553. return false;
  9554. }
  9555. i = 0;
  9556. packet->setArrayLengthByName("num_filters", collections_to_send.size());
  9557. for (itr = collections_to_send.begin(); itr != collections_to_send.end(); itr++) {
  9558. collection = itr->second;
  9559. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  9560. packet->setArrayDataByName("collection_item_num", collection->GetCollectionItemByItemID(item->details.item_id)->index, i);
  9561. i++;
  9562. }
  9563. packet->setDataByName("item_icon", item->details.icon);
  9564. packet->setDataByName("item_name", item->name.c_str());
  9565. packet->setDataByName("item_id", item->details.item_id);
  9566. packet->setDataByName("unknown3", player->GetCollectionList()->Size());
  9567. QueuePacket(packet->serialize());
  9568. safe_delete(packet);
  9569. }
  9570. return collections_to_send.size() > 0;
  9571. }
  9572. void Client::HandleCollectionAddItem(int32 collection_id, Item* item) {
  9573. Collection* collection;
  9574. struct CollectionItem* collection_item;
  9575. PacketStruct* packet;
  9576. char tmp[200] = { 0 };
  9577. assert(item);
  9578. /* first try to get the collection from the player's collection list. if it's not found, get it from the master list */
  9579. if ((collection = player->GetCollectionList()->GetCollection(collection_id))) {
  9580. /* get the item struct that represents the item for this collection */
  9581. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  9582. SendCollectionList();
  9583. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  9584. return;
  9585. }
  9586. /* sanity check */
  9587. if (collection_item->found) {
  9588. SendCollectionList();
  9589. 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());
  9590. return;
  9591. }
  9592. }
  9593. else if ((collection = master_collection_list.GetCollection(collection_id))) {
  9594. collection = new Collection(collection);
  9595. /* get the item struct that represents the item for this collection */
  9596. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  9597. SendCollectionList();
  9598. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  9599. safe_delete(collection);
  9600. return;
  9601. }
  9602. /* add the new collection to the player's collection list */
  9603. if (!player->GetCollectionList()->AddCollection(collection)) {
  9604. SendCollectionList();
  9605. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Player '%s' already has collection '%s'", player->GetName(), collection->GetName());
  9606. safe_delete(collection);
  9607. return;
  9608. }
  9609. }
  9610. else {
  9611. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find collection with id %u", collection_id);
  9612. return;
  9613. }
  9614. collection_item->found = 1;
  9615. collection->SetSaveNeeded(true);
  9616. if (!(packet = configReader.getStruct("WS_CollectionItem", version))) {
  9617. SendCollectionList();
  9618. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find struct 'WS_CollectionItem'");
  9619. return;
  9620. }
  9621. packet->setDataByName("collection_id", collection_id);
  9622. packet->setDataByName("collection_item_num", collection_item->index);
  9623. packet->setDataByName("add", 1);
  9624. QueuePacket(packet->serialize());
  9625. Item* item2 = master_item_list.GetItem(collection_item->item);
  9626. if (item2) {
  9627. Message(CHANNEL_COLOR_YELLOW, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  9628. sprintf(tmp, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  9629. SendPopupMessage(5, tmp, "quest_item", 3.5, 0x64, 0xFF, 0xFF);
  9630. }
  9631. safe_delete(packet);
  9632. RemoveItem(item, 1);
  9633. SendCollectionList();
  9634. }
  9635. void Client::DisplayCollectionComplete(Collection* collection) {
  9636. vector<struct CollectionRewardItem*>* reward_items;
  9637. vector<struct CollectionRewardItem*>* selectable_reward_items;
  9638. struct CollectionRewardItem* reward_item;
  9639. PacketStruct* packet;
  9640. int32 i;
  9641. assert(collection);
  9642. reward_items = collection->GetRewardItems();
  9643. selectable_reward_items = collection->GetSelectableRewardItems();
  9644. if (GetVersion() <= 561) {
  9645. int32 source_id = collection->GetID();
  9646. PacketStruct* packet2 = configReader.getStruct("WS_QuestRewardPackMsg", GetVersion());
  9647. if (packet2) {
  9648. packet2->setSubstructDataByName("reward_data", "unknown1", 255);
  9649. packet2->setSubstructDataByName("reward_data", "reward", "Quest Reward!");
  9650. packet2->setSubstructDataByName("reward_data", "max_coin", collection->GetRewardCoin());
  9651. packet2->setSubstructDataByName("reward_data", "exp_bonus", collection->GetRewardXP());
  9652. if(reward_items){
  9653. int32 item_count = reward_items->size();
  9654. packet2->setSubstructArrayLengthByName("reward_data", "num_rewards", item_count);
  9655. i = 0;
  9656. if(reward_items) {
  9657. for (i = 0; i < reward_items->size(); i++) {
  9658. Item* item = reward_items->at(i)->item;
  9659. if (item) {
  9660. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  9661. packet2->setItemArrayDataByName("item", item, player, i, 0, GetClientItemPacketOffset());
  9662. }
  9663. }
  9664. }
  9665. }
  9666. if (selectable_reward_items) {
  9667. packet2->setSubstructArrayLengthByName("reward_data", "num_select_rewards", selectable_reward_items->size());
  9668. for (i = 0; i < selectable_reward_items->size(); i++) {
  9669. Item* item = selectable_reward_items->at(i)->item;
  9670. if (item) {
  9671. packet2->setArrayDataByName("select_reward_id", item->details.item_id, i);
  9672. packet2->setItemArrayDataByName("select_item", item, player, i, 0, GetClientItemPacketOffset());
  9673. }
  9674. }
  9675. }
  9676. }
  9677. EQ2Packet* app = packet2->serialize();
  9678. QueuePacket(app);
  9679. safe_delete(packet2);
  9680. return;
  9681. }
  9682. if (!(packet = configReader.getStruct("WS_QuestComplete", version))) {
  9683. return;
  9684. }
  9685. packet->setDataByName("title", "Quest Reward!");
  9686. packet->setDataByName("name", collection->GetName());
  9687. packet->setDataByName("description", collection->GetCategory());
  9688. packet->setDataByName("level", collection->GetLevel());
  9689. packet->setDataByName("max_coin", collection->GetRewardCoin());
  9690. packet->setDataByName("min_coin", collection->GetRewardCoin());
  9691. //packet->setDataByName("status_points", quest->GetStatusPoints());
  9692. packet->setArrayLengthByName("num_rewards", reward_items->size());
  9693. for (i = 0; i < reward_items->size(); i++) {
  9694. reward_item = reward_items->at(i);
  9695. if(!reward_item->item)
  9696. {
  9697. LogWrite(DATABASE__ERROR, 0, "Database", "DisplayCollectionComplete Collection %s (%u) num_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  9698. Message(CHANNEL_COLOR_RED, "DisplayCollectionComplete Collection %s (%u) num_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  9699. continue;
  9700. }
  9701. packet->setArrayDataByName("reward_id", reward_item->item->details.item_id, i);
  9702. if (version < 860)
  9703. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, GetClientItemPacketOffset());
  9704. else if (version < 1193)
  9705. packet->setItemArrayDataByName("item", reward_item->item, player, i);
  9706. else
  9707. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, 2);
  9708. }
  9709. packet->setArrayLengthByName("num_select_rewards", selectable_reward_items->size());
  9710. for (i = 0; i < selectable_reward_items->size(); i++) {
  9711. reward_item = selectable_reward_items->at(i);
  9712. if(!reward_item->item)
  9713. {
  9714. LogWrite(DATABASE__ERROR, 0, "Database", "DisplayCollectionComplete Collection %s (%u) num_select_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  9715. Message(CHANNEL_COLOR_RED, "DisplayCollectionComplete Collection %s (%u) num_select_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  9716. continue;
  9717. }
  9718. packet->setArrayDataByName("select_reward_id", reward_item->item->details.item_id, i);
  9719. if (version < 860)
  9720. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, GetClientItemPacketOffset());
  9721. else if (version < 1193)
  9722. packet->setItemArrayDataByName("select_item", reward_item->item, player, i);
  9723. else
  9724. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, 2);
  9725. }
  9726. QueuePacket(packet->serialize());
  9727. safe_delete(packet);
  9728. }
  9729. void Client::HandInCollections() {
  9730. map<int32, Collection*>* collections;
  9731. map<int32, Collection*>::iterator itr;
  9732. Collection* collection;
  9733. /* only show 1 collection reward dialog at a time */
  9734. if (player->GetPendingCollectionReward()) {
  9735. return;
  9736. }
  9737. collections = player->GetCollectionList()->GetCollections();
  9738. /* 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
  9739. for this collection, this function gets called again and the process repeats until there are no more collections to hand in */
  9740. for (itr = collections->begin(); itr != collections->end(); itr++) {
  9741. collection = itr->second;
  9742. if (collection->GetIsReadyToTurnIn()) {
  9743. player->SetPendingCollectionReward(collection);
  9744. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  9745. QuestRewardData* data = new QuestRewardData;
  9746. data->quest_id = 0;
  9747. data->is_temporary = false;
  9748. data->description = std::string("");
  9749. data->is_collection = true;
  9750. data->has_displayed = false;
  9751. data->tmp_coin = 0;
  9752. data->tmp_status = 0;
  9753. data->db_saved = false;
  9754. data->db_index = 0;
  9755. quest_pending_reward.push_back(data);
  9756. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  9757. quest_updates = true;
  9758. break;
  9759. }
  9760. }
  9761. if(quest_updates) {
  9762. SaveQuestRewardData(true);
  9763. }
  9764. }
  9765. void Client::AcceptCollectionRewards(Collection* collection, int32 selectable_item_id) {
  9766. vector<struct CollectionRewardItem*>* reward_items;
  9767. vector<struct CollectionRewardItem*>::iterator itr;
  9768. struct CollectionRewardItem* reward_item;
  9769. int16 num_slots_needed;
  9770. int16 num_slots;
  9771. assert(collection);
  9772. reward_items = collection->GetRewardItems();
  9773. num_slots_needed = (int16)reward_items->size();
  9774. if (selectable_item_id > 0)
  9775. num_slots_needed++;
  9776. num_slots = player->GetPlayerItemList()->GetNumberOfFreeSlots();
  9777. if (num_slots < num_slots_needed) {
  9778. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots. Free up some slots and try again");
  9779. DisplayCollectionComplete(collection);
  9780. return;
  9781. }
  9782. /* add manditory items */
  9783. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  9784. reward_item = *itr;
  9785. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  9786. }
  9787. /* find and add the selectable item if there's one */
  9788. if (selectable_item_id > 0) {
  9789. reward_items = collection->GetSelectableRewardItems();
  9790. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  9791. reward_item = *itr;
  9792. if (reward_item->item->details.item_id == selectable_item_id) {
  9793. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  9794. break;
  9795. }
  9796. }
  9797. }
  9798. if (collection->GetRewardXP() > 0) {
  9799. player->AddXP((int32)collection->GetRewardXP());
  9800. }
  9801. if (collection->GetRewardCoin() > 0) {
  9802. player->AddCoins(collection->GetRewardCoin());
  9803. Message(CHANNEL_COLOR_YELLOW, "You receive %s", GetCoinMessage(collection->GetRewardCoin()).c_str());
  9804. }
  9805. collection->SetCompleted(true);
  9806. //update achievements for completeing collection here
  9807. collection->SetSaveNeeded(true);
  9808. SendCollectionList();
  9809. /* reset the pending collection reward and check for my collections that the player needs to hand in */
  9810. player->SetPendingCollectionReward(0);
  9811. RemoveQueuedQuestReward();
  9812. GetPlayer()->SetActiveReward(false);
  9813. HandInCollections();
  9814. GetPlayer()->GetZone()->SendSubSpawnUpdates(SUBSPAWN_TYPES::COLLECTOR);
  9815. }
  9816. void Client::SendRecipeList() {
  9817. if(GetRecipeListSent()) {
  9818. return;
  9819. }
  9820. PacketStruct* packet = 0;
  9821. map<int32, Recipe*>* recipes = player->GetRecipeList()->GetRecipes();
  9822. map<int32, Recipe*>::iterator itr;
  9823. int16 i = 0;
  9824. Recipe* recipe;
  9825. if(version <= 561) {
  9826. PacketStruct* packet = 0;
  9827. if (!(packet = configReader.getStruct("WS_UpdateRecipeBook", GetVersion()))) {
  9828. return;
  9829. }
  9830. packet->setArrayLengthByName("recipe_count", recipes->size());
  9831. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  9832. recipe = itr->second;
  9833. int32 recipe_id = recipe->GetID();
  9834. packet->setArrayDataByName("recipe_id", recipe_id, i);
  9835. packet->setArrayDataByName("recipe_data_crc", GetRecipeCRC(recipe), i);
  9836. packet->setArrayDataByName("unknown", 0x7005BE3, i); //0x7005BE3
  9837. i++;
  9838. }
  9839. //packet->PrintPacket();
  9840. EQ2Packet* ret = packet->serializeCountPacket(GetVersion(), 0, nullptr, nullptr);
  9841. QueuePacket(ret);
  9842. safe_delete(packet);
  9843. SetRecipeListSent(true);
  9844. return;
  9845. }
  9846. else if (!(packet = configReader.getStruct("WS_RecipeList", version))) {
  9847. return;
  9848. }
  9849. int8 level = player->GetTSLevel();
  9850. int index = 0;
  9851. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  9852. recipe = itr->second;
  9853. auto res = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  9854. if (res != devices.end())
  9855. index = res - devices.begin();
  9856. else
  9857. devices.push_back(recipe->GetDevice());
  9858. }
  9859. packet->setDataByName("command_type", 0);
  9860. packet->setArrayLengthByName("num_recipes", recipes->size());
  9861. int stringsize = 0;
  9862. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  9863. recipe = itr->second;
  9864. int32 myid = recipe->GetID();
  9865. int8 rlevel = recipe->GetLevel();
  9866. int8 even = level - level * .05 + .5;
  9867. int8 easymin = level - level * .25 + .5;
  9868. int8 veasymin = level - level * .35 + .5;
  9869. if (rlevel > level )
  9870. packet->setArrayDataByName("tier", 4, i);
  9871. else if ((rlevel <= level) & (rlevel >= even))
  9872. packet->setArrayDataByName("tier", 3, i);
  9873. else if ((rlevel <= even) & (rlevel >= easymin))
  9874. packet->setArrayDataByName("tier", 2, i);
  9875. else if ((rlevel <= easymin) & (rlevel >= veasymin))
  9876. packet->setArrayDataByName("tier", 1, i);
  9877. else if ((rlevel <= veasymin) & (rlevel >= 0))
  9878. packet->setArrayDataByName("tier", 0, i);
  9879. if (rlevel == 2)
  9880. int xxx = 1;
  9881. packet->setArrayDataByName("recipe_id", myid, i);
  9882. packet->setArrayDataByName("level", recipe->GetLevel(), i);
  9883. packet->setArrayDataByName("unknown1", recipe->GetLevel(), i);
  9884. packet->setArrayDataByName("icon", recipe->GetIcon(), i);
  9885. packet->setArrayDataByName("classes", recipe->GetClasses(), i);
  9886. packet->setArrayDataByName("technique", recipe->GetTechnique(), i);
  9887. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), i);
  9888. auto recipe_device = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  9889. if (recipe_device != devices.end())
  9890. packet->setArrayDataByName("device_type", recipe_device - devices.begin(), i);
  9891. else
  9892. {//TODO error should never get here
  9893. }
  9894. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), i);
  9895. packet->setArrayDataByName("recipe_name", recipe->GetName(), i);
  9896. packet->setArrayDataByName("recipe_book", recipe->GetBook(), i);
  9897. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), i);
  9898. i++;
  9899. }
  9900. //packet->PrintPacket();
  9901. EQ2Packet* pack = packet->serialize();
  9902. QueuePacket(pack);
  9903. safe_delete(packet);
  9904. SetRecipeListSent(true);
  9905. }
  9906. void Client::ShowRecipeBook() {
  9907. PacketStruct* packet = 0;
  9908. Spawn* target = 0;
  9909. int index = 0;
  9910. if (!(target = player->GetTarget())) {
  9911. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have a tradeskill device targeted");
  9912. return;
  9913. }
  9914. if (!target->IsObject()) {
  9915. return;
  9916. }
  9917. if (!(packet = configReader.getStruct("WS_ShowRecipeBook", version))) {
  9918. return;
  9919. }
  9920. packet->setDataByName("device", target->GetName());
  9921. packet->setDataByName("unknown1", 1);
  9922. auto res = std::find(devices.begin(), devices.end(), target->GetName());
  9923. if (res != devices.end()){
  9924. index = res - devices.begin();
  9925. int32 deviceID = 0;
  9926. deviceID |= 1UL << index;
  9927. //LogWrite(TRADESKILL__ERROR, 0, "Tradeskills", "GetDeviceID() = %u, deviceID = %u", ((Object*)target)->GetDeviceID(), deviceID);
  9928. packet->setDataByName("unknown2", devices.size());
  9929. packet->setDataByName("unknown3", deviceID);
  9930. }
  9931. else
  9932. packet->setDataByName("unknown2", devices.size());
  9933. QueuePacket(packet->serialize());
  9934. safe_delete(packet);
  9935. }
  9936. void Client::SendTitleUpdate() {
  9937. // must call release read lock before leaving function on GetPlayerTitles
  9938. vector<Title*>* titles = player->GetPlayerTitles()->GetAllTitles();
  9939. vector<Title*>::iterator itr;
  9940. Title* title;
  9941. sint32 i = 0;
  9942. sint32 prefix_index = database.GetCharPrefixIndex(GetCharacterID(), player);
  9943. sint32 suffix_index = database.GetCharSuffixIndex(GetCharacterID(), player);
  9944. PacketStruct* packet = configReader.getStruct("WS_TitleUpdate", GetVersion());
  9945. if (packet) {
  9946. packet->setArrayLengthByName("num_titles", titles->size());
  9947. for (itr = titles->begin(); itr != titles->end(); itr++) {
  9948. title = *itr;
  9949. packet->setArrayDataByName("title", title->GetName(), i);
  9950. packet->setArrayDataByName("prefix", title->GetPrefix(), i);
  9951. i++;
  9952. }
  9953. packet->setDataByName("current_prefix", prefix_index);
  9954. packet->setDataByName("current_suffix", suffix_index);
  9955. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  9956. #if EQDEBUG >= 9
  9957. packet->PrintPacket();
  9958. #endif
  9959. QueuePacket(packet->serialize());
  9960. safe_delete(packet);
  9961. SendUpdateTitles(prefix_index, suffix_index);
  9962. }
  9963. player->GetPlayerTitles()->ReleaseReadLock();
  9964. }
  9965. void Client::SendUpdateTitles(sint32 prefix, sint32 suffix) {
  9966. Title* suffix_title = 0;
  9967. Title* prefix_title = 0;
  9968. if (suffix != -1) {
  9969. suffix_title = player->GetPlayerTitles()->GetTitle(suffix);
  9970. if(suffix_title)
  9971. strcpy(player->appearance.suffix_title, suffix_title->GetName());
  9972. }
  9973. else
  9974. memset(player->appearance.suffix_title, 0, strlen(player->appearance.suffix_title));
  9975. if (prefix != -1) {
  9976. prefix_title = player->GetPlayerTitles()->GetTitle(prefix);
  9977. if(prefix_title)
  9978. strcpy(player->appearance.prefix_title, prefix_title->GetName());
  9979. }
  9980. else
  9981. memset(player->appearance.prefix_title, 0, strlen(player->appearance.prefix_title));
  9982. current_zone->SendUpdateTitles(this, suffix_title, prefix_title);
  9983. }
  9984. void Client::SendLanguagesUpdate(int32 id, bool setlang) {
  9985. list<Language*>* languages = player->GetPlayerLanguages()->GetAllLanguages();
  9986. list<Language*>::iterator itr;
  9987. Language* language;
  9988. int32 i = 0;
  9989. if(setlang==1){
  9990. GetPlayer()->SetCurrentLanguage(id);
  9991. }
  9992. PacketStruct* packet = configReader.getStruct("WS_Languages", GetVersion());
  9993. if (packet) {
  9994. packet->setArrayLengthByName("num_languages", languages->size());
  9995. for (itr = languages->begin(); itr != languages->end(); itr++) {
  9996. language = *itr;
  9997. packet->setArrayDataByName("language_id", language->GetID(), i);
  9998. i++;
  9999. }
  10000. packet->setDataByName("current_language", id);
  10001. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  10002. #if EQDEBUG >= 9
  10003. packet->PrintPacket();
  10004. #endif
  10005. QueuePacket(packet->serialize());
  10006. safe_delete(packet);
  10007. }
  10008. }
  10009. void Client::SendPetOptionsWindow(const char* pet_name, int8 type) {
  10010. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  10011. if (packet) {
  10012. if (pet_name)
  10013. packet->setDataByName("pet_name", pet_name);
  10014. if (player->GetInfoStruct()->get_pet_behavior() & 1)
  10015. packet->setDataByName("protect_master", 1);
  10016. if (player->GetInfoStruct()->get_pet_behavior() & 2)
  10017. packet->setDataByName("protect_self", 1);
  10018. if (player->GetInfoStruct()->get_pet_movement() == 2)
  10019. packet->setDataByName("stay_follow_toggle", 1);
  10020. packet->setDataByName("pet_type", type);
  10021. QueuePacket(packet->serialize());
  10022. }
  10023. safe_delete(packet);
  10024. }
  10025. bool Client::IsCrafting() {
  10026. return current_zone->GetTradeskillMgr()->IsClientCrafting(this);
  10027. }
  10028. void Client::SendBiography() {
  10029. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  10030. if (packet) {
  10031. char biography[512];
  10032. if(player->GetInfoStruct()->get_biography().size() < 1)
  10033. {
  10034. safe_delete(packet);
  10035. return;
  10036. }
  10037. else
  10038. {
  10039. int16 size = player->GetInfoStruct()->get_biography().size();
  10040. if(size>511)
  10041. size = 511;
  10042. strncpy(biography, player->GetInfoStruct()->get_biography().c_str(), player->GetInfoStruct()->get_biography().size());
  10043. biography[player->GetInfoStruct()->get_biography().size()] = '\0';
  10044. }
  10045. packet->setDataByName("biography", biography);
  10046. QueuePacket(packet->serialize());
  10047. }
  10048. safe_delete(packet);
  10049. }
  10050. PendingResurrection* Client::GetCurrentRez() {
  10051. return &current_rez;
  10052. }
  10053. Mutex* Client::GetResurrectMutex() {
  10054. return &m_resurrect;
  10055. }
  10056. void Client::SendResurrectionWindow() {
  10057. Spawn* caster = current_rez.caster;
  10058. if (!caster || !player)
  10059. return;
  10060. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  10061. if (!packet)
  10062. return;
  10063. char* tmp = new char[512];
  10064. sprintf(tmp, "%s would like to cast '%s' on you. Do you accept?", caster->GetName(), current_rez.spell_name.c_str());
  10065. packet->setMediumStringByName("text", tmp);
  10066. packet->setMediumStringByName("accept_text", "Yes");
  10067. packet->setMediumStringByName("cancel_text", "No");
  10068. sprintf(tmp, "accept_resurrection %u", player->GetID());
  10069. packet->setMediumStringByName("accept_command", tmp);
  10070. sprintf(tmp, "decline_resurrection %u", player->GetID());
  10071. packet->setMediumStringByName("cancel_command", tmp);
  10072. packet->setDataByName("time", current_rez.expire_timer->GetRemainingTime() / 1000);
  10073. QueuePacket(packet->serialize());
  10074. safe_delete(packet);
  10075. safe_delete_array(tmp);
  10076. }
  10077. void Client::AcceptResurrection() {
  10078. Spawn* caster = current_rez.caster;
  10079. if (!player || !caster)
  10080. return;
  10081. if (player->Alive())
  10082. return;
  10083. if ((caster->GetZone() != player->GetZone()) || (current_rez.range > 0 && player->GetDistance(caster) > current_rez.range)) {
  10084. SimpleMessage(CHANNEL_COLOR_YELLOW, "The caster must be nearby to complete the spell.");
  10085. SendResurrectionWindow();
  10086. return;
  10087. }
  10088. player->GetZone()->ResurrectSpawn(player, this);
  10089. current_rez.should_delete = true;
  10090. }
  10091. void Client::SetPendingLastName(string last_name) {
  10092. pending_last_name = new string;
  10093. pending_last_name->assign(last_name);
  10094. }
  10095. string* Client::GetPendingLastName() {
  10096. return pending_last_name;
  10097. }
  10098. void Client::RemovePendingLastName() {
  10099. safe_delete(pending_last_name);
  10100. }
  10101. void Client::SendLastNameConfirmation() {
  10102. if (!pending_last_name)
  10103. return;
  10104. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  10105. if (packet) {
  10106. char* text = new char[128];
  10107. sprintf(text, "Are you sure you want your last name to be \"%s\"?", pending_last_name->c_str());
  10108. packet->setDataByName("text", text);
  10109. packet->setDataByName("accept_text", "Yes");
  10110. packet->setDataByName("accept_command", "confirmedlastname");
  10111. packet->setDataByName("cancel_text", "No");
  10112. packet->setDataByName("max_length", 50);
  10113. packet->setDataByName("unknown4", 1);
  10114. packet->setDataByName("unknown5", 1);
  10115. QueuePacket(packet->serialize());
  10116. safe_delete(packet);
  10117. safe_delete_array(text);
  10118. }
  10119. }
  10120. void Client::AddQuestTimer(int32 quest_id) {
  10121. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  10122. quest_timers.push_back(quest_id);
  10123. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  10124. }
  10125. void Client::RemoveQuestTimer(int32 quest_id) {
  10126. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  10127. vector<int32>::iterator itr;
  10128. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  10129. if ((*itr) == quest_id) {
  10130. quest_timers.erase(itr);
  10131. break;
  10132. }
  10133. }
  10134. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  10135. }
  10136. void Client::SavePlayerImages() {
  10137. LogWrite(CCLIENT__DEBUG, 0, "Client", "Saving %s image for player %s (%u)", (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL ? "paperdoll" : "headshot"), GetPlayer()->GetName(), GetCharacterID());
  10138. // Save the paperdoll image if the server allows it
  10139. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL && rule_manager.GetGlobalRule(R_World, SavePaperdollImage)->GetBool())
  10140. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  10141. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_HEAD) {
  10142. // Save the head shot if the server allows it
  10143. if (rule_manager.GetGlobalRule(R_World, SaveHeadshotImage)->GetBool())
  10144. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  10145. // Send the head shot to the login server
  10146. if (rule_manager.GetGlobalRule(R_World, SendPaperdollImagesToLogin)->GetBool()) {
  10147. int32 size = incoming_paperdoll.current_size_bytes + CHARPICSTRUCT_MINSIZE;
  10148. ServerPacket* packet = new ServerPacket(ServerOP_CharacterPicture, size);
  10149. memset(packet->pBuffer, 0, size);
  10150. CharPictureUpdate_Struct* pic = (CharPictureUpdate_Struct*)packet->pBuffer;
  10151. pic->account_id = GetAccountID();
  10152. pic->char_id = GetCharacterID();
  10153. pic->pic_size = (int16)incoming_paperdoll.current_size_bytes;
  10154. memcpy(pic->pic, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  10155. loginserver.SendPacket(packet);
  10156. safe_delete(packet);
  10157. }
  10158. }
  10159. safe_delete_array(incoming_paperdoll.image_bytes);
  10160. incoming_paperdoll.current_size_bytes = 0;
  10161. }
  10162. void Client::EndAutoMount() {
  10163. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  10164. if (packet) {
  10165. packet->setDataByName("parameter1", 128);
  10166. packet->setDataByName("parameter2", 64);
  10167. packet->setDataByName("value", 1);
  10168. QueuePacket(packet->serialize());
  10169. safe_delete(packet);
  10170. }
  10171. packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  10172. if (packet) {
  10173. packet->setDataByName("parameter3", 4);
  10174. packet->setDataByName("parameter5", 2);
  10175. packet->setDataByName("value", 0);
  10176. QueuePacket(packet->serialize());
  10177. safe_delete(packet);
  10178. }
  10179. packet = configReader.getStruct("WS_ClearForLanding", GetVersion());
  10180. if (packet) {
  10181. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  10182. QueuePacket(packet->serialize());
  10183. safe_delete(packet);
  10184. }
  10185. on_auto_mount = false;
  10186. player->SetMount(((Player*)player)->GetTempMount());
  10187. EQ2_Color mount_color = player->GetTempMountColor();
  10188. EQ2_Color saddle_color = player->GetTempMountSaddleColor();
  10189. player->SetMountColor(&mount_color);
  10190. player->SetMountSaddleColor(&saddle_color);
  10191. player->SetTempMount(0);
  10192. }
  10193. bool Client::EntityCommandPrecheck(Spawn* spawn, const char* command) {
  10194. const char* spawn_script = spawn->GetSpawnScript();
  10195. bool should_use_spawn = true;
  10196. if (spawn_script) {
  10197. lua_State* state = lua_interface->GetSpawnScript(spawn_script);
  10198. if (state) {
  10199. Mutex* state_mutex = lua_interface->GetSpawnScriptMutex(spawn_script);
  10200. if (state_mutex)
  10201. state_mutex->writelock(__FUNCTION__, __LINE__);
  10202. lua_getglobal(state, "can_use_command");
  10203. if (lua_isfunction(state, -1)) {
  10204. lua_interface->SetSpawnValue(state, spawn);
  10205. lua_interface->SetSpawnValue(state, GetPlayer());
  10206. lua_interface->SetStringValue(state, command ? command : "");
  10207. if (lua_pcall(state, 3, 1, 0) == 0) {
  10208. should_use_spawn = lua_interface->GetBooleanValue(state, 1);
  10209. }
  10210. }
  10211. lua_interface->ResetFunctionStack(state);
  10212. if (state_mutex)
  10213. state_mutex->releasewritelock(__FUNCTION__, __LINE__);
  10214. }
  10215. }
  10216. return should_use_spawn;
  10217. }
  10218. bool Client::IsCurrentTransmuteID(int32 req_id) {
  10219. return req_id == transmuteID;
  10220. }
  10221. void Client::SetTransmuteID(int32 trans_id) {
  10222. transmuteID = trans_id;
  10223. }
  10224. int32 Client::GetTransmuteID() {
  10225. return transmuteID;
  10226. }
  10227. bool Client::HandleNewLogin(int32 account_id, int32 access_code)
  10228. {
  10229. printf("HandleNewLogin: AcctID: %i AccessCode: %i\n", account_id, access_code);
  10230. ZoneAuthRequest* zar = zone_auth.GetAuth(account_id, access_code);
  10231. if (zar)
  10232. {
  10233. int32 charID = database.GetCharacterID(zar->GetCharacterName());
  10234. if (database.IsActiveQuery(charID))
  10235. {
  10236. delayedLogin = true;
  10237. delayedAccountID = account_id;
  10238. delayedAccessKey = access_code;
  10239. delayTimer.Start(500);
  10240. 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);
  10241. return true;
  10242. }
  10243. delayedLogin = false;
  10244. delayTimer.Disable();
  10245. firstlogin = zar->isFirstLogin();
  10246. SetReadyForSpawns(false);
  10247. ready_for_updates = false;
  10248. 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);
  10249. Client* client = zone_list.GetClientByCharName(zar->GetCharacterName());
  10250. if (client || database.loadCharacter(zar->GetCharacterName(), zar->GetAccountID(), this)) {
  10251. GetPlayer()->CalculateOfflineDebtRecovery(GetLastSavedTimeStamp());
  10252. GetPlayer()->vis_changed = false;
  10253. GetPlayer()->info_changed = false;
  10254. bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
  10255. if (pvp_allowed)
  10256. this->GetPlayer()->SetAttackable(1);
  10257. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  10258. if (client) {
  10259. if (client->getConnection())
  10260. client->getConnection()->SendDisconnect(true);
  10261. bool restore_ld_success = false;
  10262. if (client->GetCurrentZone() && !client->IsZoning()) {
  10263. //swap players, allowing the client to resume his LD'd player (ONLY if same version of the client)
  10264. if (client->GetVersion() == version) {
  10265. client->DisableSave();
  10266. client->ReplaceGroupClient(this);
  10267. Player* current_player = GetPlayer();
  10268. SetPlayer(client->GetPlayer());
  10269. GetPlayer()->SetClient(this);
  10270. GetPlayer()->SetReturningFromLD(true);
  10271. SetCharacterID(client->GetCharacterID());
  10272. SetAccountID(client->GetAccountID());
  10273. SetAdminStatus(client->GetAdminStatus());
  10274. SetCurrentZone(GetPlayer()->GetZone());
  10275. client->SetPlayer(current_player);
  10276. GetPlayer()->ResetSavedSpawns();
  10277. restore_ld_success = true;
  10278. char tmpldname[128];
  10279. snprintf(tmpldname, 128, "%s Linkdead",GetPlayer()->GetName());
  10280. client->GetPlayer()->SetName(tmpldname, false);
  10281. }
  10282. ZoneServer* tmpZone = client->GetCurrentZone();
  10283. tmpZone->RemoveClientImmediately(client);
  10284. }
  10285. if(!restore_ld_success && !database.loadCharacter(zar->GetCharacterName(), zar->GetAccountID(), this)) {
  10286. LogWrite(ZONE__ERROR, 0, "Zone", "Error reloading LD character and loading DB character: %s", player->GetName());
  10287. ClientPacketFunctions::SendLoginDenied(this);
  10288. Disconnect();
  10289. return false;
  10290. }
  10291. }
  10292. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  10293. if (!GetCurrentZone()) {
  10294. LogWrite(ZONE__ERROR, 0, "Zone", "Error loading zone for character: %s", player->GetName());
  10295. ClientPacketFunctions::SendLoginDenied(this);
  10296. Disconnect();
  10297. return false;
  10298. }
  10299. else if (EQOpcodeManager.count(GetOpcodeVersion(version)) > 0 && getConnection()) {
  10300. getConnection()->SetClientVersion(version);
  10301. GetCurrentZone()->SetSpawnStructs(this);
  10302. connected_to_zone = true;
  10303. client_list.Remove(this); //remove from master client list
  10304. GetCurrentZone()->AddClient(this); //add to zones client list
  10305. zone_list.AddClientToMap(player->GetName(), this);
  10306. // 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.
  10307. if(GetCurrentZone()->IsLoading()) {
  10308. new_client_login = NewLoginState::LOGIN_DELAYED;
  10309. }
  10310. else {
  10311. new_client_login = NewLoginState::LOGIN_ALLOWED;
  10312. }
  10313. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  10314. if (zone_script && lua_interface)
  10315. lua_interface->RunZoneScript(zone_script, "new_client", GetCurrentZone(), GetPlayer());
  10316. }
  10317. else {
  10318. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  10319. version = 0;
  10320. ClientPacketFunctions::SendLoginDenied(this);
  10321. Disconnect();
  10322. return false;
  10323. }
  10324. }
  10325. else {
  10326. LogWrite(WORLD__ERROR, 0, "World", "Could not load character '%s' with account id of: %u", zar->GetCharacterName(), zar->GetAccountID());
  10327. ClientPacketFunctions::SendLoginDenied(this);
  10328. Disconnect();
  10329. return false;
  10330. }
  10331. zone_auth.RemoveAuth(zar);
  10332. }
  10333. else
  10334. {
  10335. LogWrite(WORLD__ERROR, 0, "World", "Invalid ZoneAuthRequest, disconnecting client.");
  10336. Disconnect();
  10337. return false;
  10338. }
  10339. return true;
  10340. }
  10341. void Client::SendSpawnChanges(set<Spawn*>& spawns) {
  10342. if (!IsReadyForUpdates())
  10343. return;
  10344. map<int32, SpawnData> info_changes;
  10345. map<int32, SpawnData> pos_changes;
  10346. map<int32, SpawnData> vis_changes;
  10347. map<int32, SpawnData> empty_changes;
  10348. int32 info_size = 0;
  10349. int32 pos_size = 0;
  10350. int32 vis_size = 0;
  10351. int count = 0;
  10352. for (const auto& spawn : spawns) {
  10353. int16 index = GetPlayer()->GetIndexForSpawn(spawn);
  10354. if (index == 0 || !GetPlayer()->WasSentSpawn(spawn->GetID()))
  10355. continue;
  10356. if(GetPlayer() == spawn && GetVersion() <= 284) { // stopped self client/player warping in the EQ2 release disc (Beta), don't send yourself in bulk spawn updates
  10357. continue;
  10358. }
  10359. int16 tmp_info_size = 0;
  10360. int16 tmp_pos_size = 0;
  10361. int16 tmp_vis_size = 0;
  10362. if (spawn->vis_changed)
  10363. {
  10364. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion(), &tmp_vis_size);
  10365. if (vis_change) {
  10366. SpawnData data;
  10367. data.spawn = spawn;
  10368. data.data = vis_change;
  10369. data.size = tmp_vis_size;
  10370. map<int32, SpawnData> tmp_vis_changes;
  10371. tmp_vis_changes[index] = data;
  10372. map<int32, SpawnData> tmp_info_changes;
  10373. map<int32, SpawnData> tmp_pos_changes;
  10374. if (spawn->info_changed) {
  10375. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion(), &tmp_info_size);
  10376. if (info_change) {
  10377. SpawnData data;
  10378. data.spawn = spawn;
  10379. data.data = info_change;
  10380. data.size = tmp_info_size;
  10381. tmp_info_changes[index] = data;
  10382. }
  10383. }
  10384. if (spawn->position_changed) {
  10385. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion(), &tmp_pos_size);
  10386. if (pos_change) {
  10387. SpawnData data;
  10388. data.spawn = spawn;
  10389. data.data = pos_change;
  10390. data.size = tmp_pos_size;
  10391. tmp_pos_changes[index] = data;
  10392. }
  10393. }
  10394. MakeSpawnChangePacket(tmp_info_changes, tmp_pos_changes, tmp_vis_changes, tmp_info_size, tmp_pos_size, data.size);
  10395. for (auto& kv : tmp_info_changes) {
  10396. safe_delete_array(kv.second.data);
  10397. }
  10398. for (auto& kv : tmp_pos_changes) {
  10399. safe_delete_array(kv.second.data);
  10400. }
  10401. for (auto& kv : tmp_vis_changes) {
  10402. safe_delete_array(kv.second.data);
  10403. }
  10404. continue;
  10405. }
  10406. }
  10407. if (spawn->info_changed) {
  10408. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion(), &tmp_info_size);
  10409. if (info_change) {
  10410. SpawnData data;
  10411. data.spawn = spawn;
  10412. data.data = info_change;
  10413. data.size = tmp_info_size;
  10414. info_size += tmp_info_size;
  10415. info_changes[index] = data;
  10416. }
  10417. count++;
  10418. }
  10419. if (spawn->position_changed) {
  10420. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion(), &tmp_pos_size);
  10421. if (pos_change) {
  10422. SpawnData data;
  10423. data.spawn = spawn;
  10424. data.data = pos_change;
  10425. data.size = tmp_pos_size;
  10426. pos_size += tmp_pos_size;
  10427. pos_changes[index] = data;
  10428. }
  10429. count++;
  10430. }
  10431. if (spawn->vis_changed) {
  10432. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion(), &tmp_vis_size);
  10433. if (vis_change) {
  10434. SpawnData data;
  10435. data.spawn = spawn;
  10436. data.data = vis_change;
  10437. data.size = tmp_vis_size;
  10438. vis_size += tmp_vis_size;
  10439. vis_changes[index] = data;
  10440. }
  10441. count++;
  10442. }
  10443. }
  10444. if (info_size == 0 && pos_size == 0 && vis_size == 0) {
  10445. return;
  10446. }
  10447. MakeSpawnChangePacket(info_changes, pos_changes, vis_changes, info_size, pos_size, vis_size);
  10448. for (auto& kv : info_changes) {
  10449. safe_delete_array(kv.second.data);
  10450. }
  10451. for (auto& kv : pos_changes) {
  10452. safe_delete_array(kv.second.data);
  10453. }
  10454. for (auto& kv : vis_changes) {
  10455. safe_delete_array(kv.second.data);
  10456. }
  10457. }
  10458. 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)
  10459. {
  10460. static const int8 oversized = 255;
  10461. int16 opcode_val = 0;
  10462. if (EQOpcodeManager.count(GetOpcodeVersion(version)) != 0) {
  10463. opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd);
  10464. }
  10465. int32 size = info_size + pos_size + vis_size + 8;
  10466. size += CheckOverLoadSize(info_size);
  10467. size += CheckOverLoadSize(pos_size);
  10468. size += CheckOverLoadSize(vis_size);
  10469. if (version <= 373 && size >= 255) {//1 byte to 3 for overloaded val
  10470. size += 2;
  10471. }
  10472. else if (version >= 374)
  10473. size += 3;
  10474. uchar* tmp = new uchar[size];
  10475. uchar* ptr = tmp;
  10476. memset(tmp, 0, size);
  10477. if (version <= 373) {
  10478. if (size >= 255) {
  10479. size -= 3;
  10480. memcpy(ptr, &oversized, sizeof(int8));
  10481. ptr += sizeof(int8);
  10482. memcpy(ptr, &size, sizeof(int16));
  10483. ptr += sizeof(int16);
  10484. size += 3;
  10485. }
  10486. else {
  10487. size -= 1;
  10488. memcpy(ptr, &size, sizeof(int8));
  10489. ptr += sizeof(int8);
  10490. size += 1;
  10491. }
  10492. }
  10493. else {
  10494. size -= 4;
  10495. memcpy(ptr, &size, sizeof(int32));
  10496. ptr += sizeof(int32);
  10497. size += 4;
  10498. }
  10499. memcpy(ptr, &oversized, sizeof(int8));
  10500. ptr += sizeof(int8);
  10501. memcpy(ptr, &opcode_val, sizeof(int16));
  10502. ptr += sizeof(int16);
  10503. int32 current_time = Timer::GetCurrentTime2();
  10504. memcpy(ptr, &current_time, sizeof(int32));
  10505. ptr += sizeof(int32);
  10506. ptr += DoOverLoad(info_size, ptr);
  10507. for (const auto& kv : info_changes) {
  10508. auto info = kv.second;
  10509. memcpy(ptr, info.data, info.size);
  10510. ptr += info.size;
  10511. }
  10512. ptr += DoOverLoad(pos_size, ptr);
  10513. for (const auto& kv : pos_changes) {
  10514. auto pos = kv.second;
  10515. memcpy(ptr, pos.data, pos.size);
  10516. ptr += pos.size;
  10517. }
  10518. ptr += DoOverLoad(vis_size, ptr);
  10519. for (const auto& kv : vis_changes) {
  10520. auto vis = kv.second;
  10521. memcpy(ptr, vis.data, vis.size);
  10522. ptr += vis.size;
  10523. }
  10524. EQ2Packet* packet = new EQ2Packet(OP_ClientCmdMsg, tmp, size);
  10525. if (packet) {
  10526. /*char blah[64];
  10527. snprintf(blah, 64, "Sending %i", current_time);
  10528. SimpleMessage(4, blah);*/
  10529. QueuePacket(packet);
  10530. }
  10531. delete[] tmp;
  10532. }
  10533. void Client::SendHailCommand(Spawn* spawn)
  10534. {
  10535. // hardcoded 'hail' entity commands
  10536. switch (spawn->secondary_command_list_id)
  10537. {
  10538. case 9:
  10539. case 1262:
  10540. case 1265:
  10541. case 1267:
  10542. {
  10543. EQ2_16BitString* command = new EQ2_16BitString();
  10544. command->data = "";
  10545. command->size = 0;
  10546. commands.Process(COMMAND_HAIL, command, this, spawn);
  10547. safe_delete(command);
  10548. break;
  10549. }
  10550. }
  10551. }
  10552. void Client::SendDefaultCommand(Spawn* spawn, const char* command, float distance)
  10553. {
  10554. if (GetPlayer()->WasSentSpawn(spawn->GetID())) {
  10555. PacketStruct* packet = configReader.getStruct("WS_SetDefaultCommand", GetVersion());
  10556. if (packet) {
  10557. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  10558. packet->setMediumStringByName("command_name", command);
  10559. packet->setDataByName("distance", distance);
  10560. QueuePacket(packet->serialize());
  10561. safe_delete(packet);
  10562. }
  10563. }
  10564. }
  10565. bool Client::HandleHouseEntityCommands(Spawn* spawn, int32 spawnid, string command)
  10566. {
  10567. if (GetCurrentZone()->GetInstanceType() != PERSONAL_HOUSE_INSTANCE)
  10568. return false;
  10569. if (command == "house_spawn_examine")
  10570. {
  10571. uint32 itemID = spawn->GetPickupItemID();
  10572. if (itemID)
  10573. {
  10574. Item* item = master_item_list.GetItem(itemID);
  10575. if (item)
  10576. {
  10577. EQ2Packet* app = item->serialize(GetVersion(), true, GetPlayer());
  10578. //DumpPacket(app);
  10579. QueuePacket(app);
  10580. }
  10581. }
  10582. return true;
  10583. }
  10584. return false;
  10585. }
  10586. bool Client::PopulateHouseSpawn(PacketStruct* place_object)
  10587. {
  10588. if (GetTempPlacementSpawn())
  10589. {
  10590. Spawn* tmp = GetTempPlacementSpawn();
  10591. int32 spawn_group_id = database.GetNextSpawnLocation();
  10592. tmp->SetSpawnLocationID(spawn_group_id);
  10593. float newHeading = place_object->getType_float_ByName("heading") + 180;
  10594. int32 spawnDBID = 0;
  10595. if (GetCurrentZone()->house_object_database_lookup.count(tmp->GetModelType()) > 0)
  10596. {
  10597. spawnDBID = GetCurrentZone()->house_object_database_lookup.Get(tmp->GetModelType());
  10598. tmp->SetDatabaseID(spawnDBID);
  10599. }
  10600. else
  10601. {
  10602. spawnDBID = database.FindHouseInstanceSpawn(tmp);
  10603. if (spawnDBID)
  10604. {
  10605. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), spawnDBID);
  10606. tmp->SetDatabaseID(spawnDBID);
  10607. }
  10608. }
  10609. tmp->SetX(place_object->getType_float_ByName("x"));
  10610. tmp->SetY(place_object->getType_float_ByName("y"));
  10611. tmp->SetZ(place_object->getType_float_ByName("z"));
  10612. tmp->SetHeading(newHeading);
  10613. tmp->SetSpawnOrigX(tmp->GetX());
  10614. tmp->SetSpawnOrigY(tmp->GetY());
  10615. tmp->SetSpawnOrigZ(tmp->GetZ());
  10616. tmp->SetSpawnOrigHeading(tmp->GetHeading());
  10617. database.SaveSpawnInfo(tmp);
  10618. database.SaveSpawnEntry(tmp, "houseplacement", 100, 0, 0, 0);
  10619. if (!spawnDBID)
  10620. {
  10621. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), tmp->GetDatabaseID());
  10622. // we need to copy as to not delete the ZoneServer object_list entry this on house item pickup
  10623. GetCurrentZone()->AddObject(tmp->GetDatabaseID(), ((Object*)tmp)->Copy());
  10624. }
  10625. return true;
  10626. }
  10627. return false;
  10628. }
  10629. bool Client::PopulateHouseSpawnFinalize()
  10630. {
  10631. if (GetTempPlacementSpawn())
  10632. {
  10633. Spawn* tmp = GetTempPlacementSpawn();
  10634. GetCurrentZone()->AddSpawn(tmp);
  10635. GetCurrentZone()->SendSpawnChanges(tmp, this);
  10636. SetTempPlacementSpawn(nullptr);
  10637. int32 uniqueID = GetPlacementUniqueItemID();
  10638. Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  10639. tmp->SetPickupItemID(uniqueItem->details.item_id);
  10640. tmp->SetPickupUniqueItemID(uniqueID);
  10641. if (uniqueItem)
  10642. {
  10643. if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE)
  10644. {
  10645. Query query;
  10646. 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);
  10647. }
  10648. if(uniqueItem->GetItemScript() &&
  10649. lua_interface->RunItemScript(uniqueItem->GetItemScript(), "placed", uniqueItem, GetPlayer(), tmp))
  10650. {
  10651. uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  10652. }
  10653. if(uniqueItem) {
  10654. database.DeleteItem(GetCharacterID(), uniqueItem, 0);
  10655. GetPlayer()->item_list.RemoveItem(uniqueItem, true);
  10656. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  10657. }
  10658. SetPlacementUniqueItemID(0);
  10659. }
  10660. return true;
  10661. }
  10662. return false;
  10663. }
  10664. void Client::SendMoveObjectMode(Spawn* spawn, uint8 placementMode, float unknown2_3)
  10665. {
  10666. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", GetVersion());
  10667. packet->setDataByName("placement_mode", placementMode);
  10668. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  10669. packet->setDataByName("model_type", spawn->GetModelType());
  10670. packet->setDataByName("unknown", 1); //size
  10671. packet->setDataByName("unknown2", 1); //size 2
  10672. packet->setDataByName("unknown2", .5, 1); //size 3
  10673. packet->setDataByName("unknown2", 3, 2);
  10674. packet->setDataByName("unknown2", unknown2_3, 3);
  10675. packet->setDataByName("max_distance", 500);
  10676. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  10677. QueuePacket(packet->serialize());
  10678. safe_delete(packet);
  10679. }
  10680. void Client::SendFlightAutoMount(int32 path_id, int16 mount_id, int8 mount_red_color, int8 mount_green_color, int8 mount_blue_color)
  10681. {
  10682. SetPendingFlightPath(path_id);
  10683. ((Player*)player)->SetTempMount(((Entity*)player)->GetMount());
  10684. ((Player*)player)->SetTempMountColor(((Entity*)player)->GetMountColor());
  10685. ((Player*)player)->SetTempMountSaddleColor(((Entity*)player)->GetMountSaddleColor());
  10686. PacketStruct* packet = configReader.getStruct("WS_ReadyForTakeOff", GetVersion());
  10687. if (packet) {
  10688. QueuePacket(packet->serialize());
  10689. safe_delete(packet);
  10690. }
  10691. if (mount_id)
  10692. ((Entity*)GetPlayer())->SetMount(mount_id, mount_red_color, mount_green_color, mount_blue_color);
  10693. }
  10694. void Client::SendShowBook(Spawn* sender, string title, int8 language, int8 num_pages, ...)
  10695. {
  10696. if (!sender)
  10697. {
  10698. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  10699. return;
  10700. }
  10701. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  10702. if (!packet) {
  10703. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  10704. return;
  10705. }
  10706. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  10707. packet->setDataByName("book_title", title.c_str());
  10708. packet->setDataByName("book_type", "simple");
  10709. packet->setDataByName("unknown2", 1);
  10710. if(language > 0 && !GetPlayer()->HasLanguage(language))
  10711. packet->setDataByName("language", language);
  10712. if (GetVersion() > 561)
  10713. packet->setDataByName("unknown5", 1, 4);
  10714. packet->setArrayLengthByName("num_pages", num_pages);
  10715. va_list args;
  10716. va_start(args, num_pages);
  10717. std::string endString("");
  10718. for (int8 p = 0; p < num_pages; p++)
  10719. {
  10720. std::string page = va_arg(args, string);
  10721. switch (GetVersion())
  10722. {
  10723. // release client
  10724. case 283:
  10725. case 373: // trial isle client
  10726. {
  10727. endString.append(page);
  10728. break;
  10729. }
  10730. // DoF trial
  10731. case 546:
  10732. case 561:
  10733. {
  10734. if (p == 0)
  10735. packet->setDataByName("cover_page", page.c_str());
  10736. else
  10737. packet->setArrayDataByName("page_text", page.c_str(), p - 1);
  10738. break;
  10739. }
  10740. // all other clients
  10741. default:
  10742. {
  10743. packet->setArrayDataByName("page_text", page.c_str(), p);
  10744. break;
  10745. }
  10746. }
  10747. }
  10748. if (GetVersion() <= 373)
  10749. {
  10750. packet->setDataByName("page_text", endString.c_str());
  10751. }
  10752. va_end(args);
  10753. QueuePacket(packet->serialize());
  10754. safe_delete(packet);
  10755. }
  10756. void Client::SendShowBook(Spawn* sender, string title, int8 language, vector<Item::BookPage*> pages)
  10757. {
  10758. if (!sender)
  10759. {
  10760. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  10761. return;
  10762. }
  10763. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  10764. if (!packet) {
  10765. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  10766. return;
  10767. }
  10768. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  10769. packet->setDataByName("book_title", title.c_str());
  10770. packet->setDataByName("book_type", "simple");
  10771. packet->setDataByName("unknown2", 1);
  10772. if(language > 0 && !GetPlayer()->HasLanguage(language))
  10773. packet->setDataByName("language", language);
  10774. if (GetVersion() > 561)
  10775. packet->setDataByName("unknown5", 1, 4);
  10776. packet->setArrayLengthByName("num_pages", pages.size());
  10777. std::string endString("");
  10778. for (int8 p = 0; p < pages.size(); p++)
  10779. {
  10780. Item::BookPage* page = pages[p];
  10781. std::string pageText = string(page->page_text.data);
  10782. switch (GetVersion())
  10783. {
  10784. // release client
  10785. case 283:
  10786. case 373: // trial isle client
  10787. {
  10788. endString.append(pageText);
  10789. break;
  10790. }
  10791. // DoF trial
  10792. case 546:
  10793. case 561:
  10794. {
  10795. if (p == 0)
  10796. packet->setDataByName("cover_page", pageText.c_str());
  10797. else
  10798. packet->setArrayDataByName("page_text", pageText.c_str(), p - 1);
  10799. break;
  10800. }
  10801. // all other clients
  10802. default:
  10803. {
  10804. int8 valign = int8(page->valign);
  10805. int8 halign = int8(page->halign);
  10806. packet->setArrayDataByName("page_text", pageText.c_str(), p);
  10807. packet->setArrayDataByName("page_text_valign", valign, p);
  10808. packet->setArrayDataByName("page_text_halign", halign, p);
  10809. break;
  10810. }
  10811. }
  10812. }
  10813. if (GetVersion() == 283)
  10814. {
  10815. packet->setDataByName("page_text", endString.c_str());
  10816. }
  10817. QueuePacket(packet->serialize());
  10818. safe_delete(packet);
  10819. }
  10820. void Client::ReplaceGroupClient(Client* new_client)
  10821. {
  10822. if (this->GetPlayer()->GetGroupMemberInfo())
  10823. {
  10824. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  10825. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  10826. if(group)
  10827. {
  10828. group->MGroupMembers.writelock();
  10829. rejoin_group_id = this->GetPlayer()->GetGroupMemberInfo()->group_id;
  10830. this->GetPlayer()->GetGroupMemberInfo()->client = new_client;
  10831. this->GetPlayer()->GetGroupMemberInfo()->member = GetPlayer();
  10832. group->MGroupMembers.releasewritelock();
  10833. }
  10834. else
  10835. {
  10836. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  10837. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  10838. this->GetPlayer()->SetGroupMemberInfo(0);
  10839. }
  10840. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  10841. }
  10842. }
  10843. void Client::TempRemoveGroup()
  10844. {
  10845. if (this->GetPlayer()->GetGroupMemberInfo())
  10846. {
  10847. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  10848. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  10849. if(group)
  10850. {
  10851. group->MGroupMembers.writelock();
  10852. rejoin_group_id = this->GetPlayer()->GetGroupMemberInfo()->group_id;
  10853. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  10854. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  10855. this->GetPlayer()->SetGroupMemberInfo(0);
  10856. group->MGroupMembers.releasewritelock();
  10857. group->RemoveClientReference(this);
  10858. }
  10859. else
  10860. {
  10861. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  10862. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  10863. this->GetPlayer()->SetGroupMemberInfo(0);
  10864. }
  10865. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  10866. }
  10867. }
  10868. void Client::CreateMail(int32 charID, std::string fromName, std::string subjectName, std::string mailBody,
  10869. int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time)
  10870. {
  10871. Mail mail;
  10872. mail.mail_id = 0;
  10873. mail.already_read = 0;
  10874. mail.postage_cost = 0;
  10875. mail.attachment_cost = 0;
  10876. mail.save_needed = 1;
  10877. //uhh...mail has std::strings so
  10878. //memset(&mail,0,sizeof(Mail));
  10879. mail.player_to_id = charID;
  10880. mail.player_from = fromName;
  10881. mail.subject = subjectName;
  10882. mail.mail_body = mailBody;
  10883. mail.mail_type = mailType;
  10884. mail.coin_copper = copper;
  10885. mail.coin_silver = silver;
  10886. mail.coin_gold = gold;
  10887. mail.coin_plat = platinum;
  10888. mail.char_item_id = item_id;
  10889. mail.stack = stack_size;
  10890. mail.time_sent = time_sent;
  10891. mail.expire_time = expire_time;
  10892. database.SavePlayerMail(&mail);
  10893. }
  10894. void Client::CreateAndUpdateMail(std::string fromName, std::string subjectName, std::string mailBody,
  10895. int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time)
  10896. {
  10897. Mail* mail = new Mail();
  10898. mail->player_to_id = GetCharacterID();
  10899. mail->player_from = fromName;
  10900. mail->subject = subjectName;
  10901. mail->mail_body = mailBody;
  10902. mail->mail_type = mailType;
  10903. mail->coin_copper = copper;
  10904. mail->coin_silver = silver;
  10905. mail->coin_gold = gold;
  10906. mail->coin_plat = platinum;
  10907. mail->char_item_id = item_id;
  10908. mail->stack = stack_size;
  10909. mail->time_sent = time_sent;
  10910. mail->expire_time = expire_time;
  10911. mail->postage_cost = 0;
  10912. mail->save_needed = 1;
  10913. mail->already_read = 0;
  10914. database.SavePlayerMail(mail);
  10915. GetPlayer()->AddMail(mail);
  10916. }
  10917. void Client::SendEquipOrInvUpdateBySlot(int8 slot)
  10918. {
  10919. if(slot < NUM_SLOTS)
  10920. {
  10921. EQ2Packet* app = GetPlayer()->GetEquipmentList()->serialize(GetVersion(), GetPlayer());
  10922. if (app)
  10923. QueuePacket(app);
  10924. }
  10925. else
  10926. {
  10927. EQ2Packet* outapp = GetPlayer()->SendInventoryUpdate(GetVersion());
  10928. if (outapp)
  10929. QueuePacket(outapp);
  10930. }
  10931. }
  10932. void Client::QueueStateCommand(int32 spawn_player_id, int32 state)
  10933. {
  10934. if(spawn_player_id < 1)
  10935. return;
  10936. MQueueStateCmds.writelock();
  10937. queued_state_commands.insert(make_pair(spawn_player_id, state));
  10938. MQueueStateCmds.releasewritelock();
  10939. }
  10940. void Client::ProcessStateCommands()
  10941. {
  10942. if(!IsReadyForUpdates())
  10943. return;
  10944. MQueueStateCmds.writelock();
  10945. map<int32, int32>::iterator itr = queued_state_commands.begin();
  10946. for(; itr != queued_state_commands.end(); itr++)
  10947. ClientPacketFunctions::SendStateCommand(this, itr->first, itr->second);
  10948. queued_state_commands.clear();
  10949. MQueueStateCmds.releasewritelock();
  10950. }
  10951. void Client::PurgeItem(Item* item)
  10952. {
  10953. std::unique_lock lock(MConversation);
  10954. map<int32, Item*>::iterator itr;
  10955. for(itr = conversation_items.begin(); itr != conversation_items.end(); itr++)
  10956. {
  10957. if ( itr->second == item )
  10958. {
  10959. conversation_items.erase(itr);
  10960. break;
  10961. }
  10962. }
  10963. }
  10964. void Client::ConsumeFoodDrink(Item* item, int32 slot)
  10965. {
  10966. if(GetPlayer()->StopSaveSpellEffects())
  10967. return;
  10968. if(item) {
  10969. LogWrite(MISC__INFO, 1, "Command", "ItemID: %u, ItemName: %s ItemCount: %i ", item->details.item_id, item->name.c_str(), item->details.count);
  10970. if(item->GetItemScript() && lua_interface){
  10971. lua_interface->RunItemScript(item->GetItemScript(), "cast", item, GetPlayer());
  10972. if (slot == 22)
  10973. Message(CHANNEL_NARRATIVE, "You eat a %s.", item->name.c_str());
  10974. else
  10975. Message(CHANNEL_NARRATIVE, "You drink a %s.", item->name.c_str());
  10976. }
  10977. else {
  10978. Message(CHANNEL_NARRATIVE, "SERVER BUG! Item Script not assigned for consuming '%s'.", item->name.c_str());
  10979. return;
  10980. }
  10981. if (item->details.count > 1) {
  10982. item->details.count -= 1;
  10983. item->save_needed = true;
  10984. }
  10985. else {
  10986. database.DeleteItem(GetPlayer()->GetCharacterID(), item, "EQUIPPED");
  10987. GetPlayer()->GetEquipmentList()->RemoveItem(slot, true);
  10988. }
  10989. GetPlayer()->SetCharSheetChanged(true);
  10990. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  10991. if(GetVersion() <= 373) {
  10992. EQ2Packet* outapp = GetPlayer()->SendInventoryUpdate(GetVersion());
  10993. QueuePacket(outapp);
  10994. }
  10995. }
  10996. }
  10997. void Client::AwardCoins(int64 total_coins, std::string reason)
  10998. {
  10999. if (total_coins > 0) {
  11000. player->AddCoins(total_coins);
  11001. PlaySound("coin_cha_ching");
  11002. char tmp[64] = { 0 };
  11003. string message = "You receive ";
  11004. int32 val = 0;
  11005. if (total_coins >= 1000000) {
  11006. val = total_coins / 1000000;
  11007. total_coins -= 1000000 * val;
  11008. sprintf(tmp, "%u Platinum ", val);
  11009. message.append(tmp);
  11010. memset(tmp, 0, 64);
  11011. }
  11012. if (total_coins >= 10000) {
  11013. val = total_coins / 10000;
  11014. total_coins -= 10000 * val;
  11015. sprintf(tmp, "%u Gold ", val);
  11016. message.append(tmp);
  11017. memset(tmp, 0, 64);
  11018. }
  11019. if (total_coins >= 100) {
  11020. val = total_coins / 100;
  11021. total_coins -= 100 * val;
  11022. sprintf(tmp, "%u Silver ", val);
  11023. message.append(tmp);
  11024. memset(tmp, 0, 64);
  11025. }
  11026. if (total_coins > 0) {
  11027. sprintf(tmp, "%u Copper ", (int32)total_coins);
  11028. message.append(tmp);
  11029. }
  11030. message.append(reason);
  11031. int8 type = CHANNEL_LOOT;
  11032. SimpleMessage(type, message.c_str());
  11033. }
  11034. }
  11035. void Client::TriggerSpellSave()
  11036. {
  11037. int32 interval = rule_manager.GetGlobalRule(R_Spells, PlayerSpellSaveStateWaitInterval)->GetInt32();
  11038. // default to not have some bogus value in the rule
  11039. if(interval < 1)
  11040. interval = 100;
  11041. MSaveSpellStateMutex.lock();
  11042. if(!save_spell_state_timer.Enabled())
  11043. {
  11044. save_spell_state_time_bucket = 0;
  11045. save_spell_state_timer.Start(interval, true);
  11046. }
  11047. else
  11048. {
  11049. int32 elapsed_time = save_spell_state_timer.GetElapsedTime();
  11050. save_spell_state_time_bucket += elapsed_time;
  11051. int32 save_wait_cap = rule_manager.GetGlobalRule(R_Spells, PlayerSpellSaveStateCap)->GetInt32();
  11052. // default to not have some bogus value in the rule
  11053. if(save_wait_cap < interval)
  11054. save_wait_cap = interval+1;
  11055. if(save_spell_state_time_bucket >= save_wait_cap)
  11056. {
  11057. save_spell_state_timer.Trigger();
  11058. }
  11059. }
  11060. MSaveSpellStateMutex.unlock();
  11061. }
  11062. void Client::UpdateSentSpellList() {
  11063. MSpellDetails.readlock(__FUNCTION__, __LINE__);
  11064. std::map<int32, int32>::iterator itr;
  11065. for(itr = sent_spell_details.begin(); itr != sent_spell_details.end(); itr++) {
  11066. Spell* spell = master_spell_list.GetSpell(itr->first, itr->second);
  11067. EQ2Packet* app = spell->SerializeSpell(this, false, false);
  11068. QueuePacket(app);
  11069. }
  11070. MSpellDetails.releasereadlock(__FUNCTION__, __LINE__);
  11071. }
  11072. void Client::SetTempPlacementSpawn(Spawn* tmp) {
  11073. tempPlacementSpawn = tmp;
  11074. hasSentTempPlacementSpawn = false;
  11075. if(tempPlacementSpawn)
  11076. temp_placement_timer.Start();
  11077. else
  11078. temp_placement_timer.Disable();
  11079. }
  11080. void Client::SetPlayer(Player* new_player) {
  11081. if (player && player != new_player)
  11082. zone_list.RemoveClientFromMap(player->GetName(), this);
  11083. player = new_player;
  11084. player->SetClient(this);
  11085. }
  11086. bool Client::UseItem(Item* item, Spawn* target) {
  11087. if (item && item->GetItemScript()) {
  11088. int16 item_index = item->details.index;
  11089. if(!item->CheckFlag2(INDESTRUCTABLE) && item->generic_info.condition == 0) {
  11090. SimpleMessage(CHANNEL_COLOR_RED, "This item is broken and must be repaired at a mender before it can be used");
  11091. }
  11092. else if (item->CheckFlag(EVIL_ONLY) && GetPlayer()->GetAlignment() != ALIGNMENT_EVIL) {
  11093. Message(0, "%s requires an evil race.", item->name.c_str());
  11094. }
  11095. else if (item->CheckFlag(GOOD_ONLY) && GetPlayer()->GetAlignment() != ALIGNMENT_GOOD) {
  11096. Message(0, "%s requires a good race.", item->name.c_str());
  11097. }
  11098. else if (item->generic_info.max_charges == 0 || item->generic_info.max_charges == 0xFFFF) {
  11099. lua_interface->RunItemScript(item->GetItemScript(), "used", item, player, target);
  11100. return true;
  11101. }
  11102. else {
  11103. if (item->details.count > 0) {
  11104. std::string itemName = string(item->name);
  11105. int32 item_id = item->details.item_id;
  11106. sint64 flags = 0;
  11107. if(lua_interface->RunItemScript(item->GetItemScript(), "used", item, player, target, &flags) && flags >= 0)
  11108. {
  11109. //reobtain item make sure it wasn't removed
  11110. item = player->item_list.GetItemFromIndex(item_index);
  11111. if(!item) {
  11112. 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);
  11113. return true;
  11114. }
  11115. else if(!item->generic_info.display_charges && item->generic_info.max_charges == 1) {
  11116. Message(CHANNEL_NARRATIVE, "%s is out of charges. It has been removed.", item->name.c_str());
  11117. RemoveItem(item, 1); // end of a set of charges OR an item that uses a stack count of actual item quantity
  11118. return true;
  11119. }
  11120. else
  11121. {
  11122. item->details.count--; // charges
  11123. item->save_needed = true;
  11124. QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  11125. if(!item->details.count) {
  11126. Message(CHANNEL_NARRATIVE, "%s is out of charges. It has been removed.", item->name.c_str());
  11127. RemoveItem(item, 1); // end of a set of charges OR an item that uses a stack count of actual item quantity
  11128. }
  11129. return true;
  11130. }
  11131. }
  11132. else {
  11133. 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);
  11134. return true;
  11135. }
  11136. }
  11137. else
  11138. {
  11139. //reobtain item make sure it wasn't removed
  11140. item = player->item_list.GetItemFromIndex(item_index);
  11141. SimpleMessage(CHANNEL_COLOR_YELLOW, "Item is out of charges.");
  11142. if(item) {
  11143. 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);
  11144. }
  11145. }
  11146. }
  11147. }
  11148. return false;
  11149. }
  11150. void Client::SendPlayFlavor(Spawn* spawn, int8 language, VoiceOverStruct* non_garble,
  11151. VoiceOverStruct* garble, bool success, bool garble_success) {
  11152. VoiceOverStruct* resStruct = nullptr;
  11153. if(language == 0 || GetPlayer()->HasLanguage(language)) {
  11154. if(success) {
  11155. resStruct = non_garble;
  11156. }
  11157. }
  11158. else if(garble_success) {
  11159. resStruct = garble;
  11160. }
  11161. if(resStruct) {
  11162. 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);
  11163. }
  11164. }
  11165. void Client::SaveQuestRewardData(bool force_refresh) {
  11166. Query query;
  11167. if(force_refresh) {
  11168. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete from character_quest_rewards where char_id = %u",
  11169. GetCharacterID());
  11170. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete from character_quest_temporary_rewards where char_id = %u",
  11171. GetCharacterID());
  11172. }
  11173. vector<QuestRewardData*>::iterator itr;
  11174. vector<QuestRewardData*> tmp_quest_rewards;
  11175. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  11176. int index = 0;
  11177. for (itr = quest_pending_reward.begin(); itr != quest_pending_reward.end(); itr++) {
  11178. int32 questID = (*itr)->quest_id;
  11179. if(!(*itr)->db_saved || force_refresh) {
  11180. 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')",
  11181. 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());
  11182. (*itr)->db_saved = true;
  11183. (*itr)->db_index = index;
  11184. if(questID && (*itr)->is_temporary) {
  11185. std::vector<Item*> items;
  11186. GetPlayer()->GetQuestTemporaryRewards(questID, &items);
  11187. if(!force_refresh && items.size() > 0) {
  11188. query.AddQueryAsync(GetCharacterID(), &database, Q_REPLACE, "delete from character_quest_temporary_rewards where char_id = %u and quest_id = %u",
  11189. GetCharacterID(), questID);
  11190. }
  11191. for(int i=0;i<items.size();i++) {
  11192. query.AddQueryAsync(GetCharacterID(), &database, Q_REPLACE, "replace into character_quest_temporary_rewards (char_id, quest_id, item_id, count) values(%u, %u, %u, %u)",
  11193. GetCharacterID(), questID, items[i]->details.item_id, items[i]->details.count);
  11194. }
  11195. }
  11196. }
  11197. index++;
  11198. }
  11199. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  11200. }
  11201. void Client::UpdateCharacterRewardData(QuestRewardData* data) {
  11202. if(!data)
  11203. return;
  11204. if(data->db_saved) {
  11205. Query query;
  11206. 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",
  11207. 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);
  11208. }
  11209. }
  11210. void Client::AddRecipeToPlayerPack(Recipe* recipe, PacketStruct* packet, int16* i) {
  11211. int index = 0;
  11212. if(recipe == nullptr)
  11213. return;
  11214. PlayerRecipeList* prl = GetPlayer()->GetRecipeList();
  11215. if (prl->GetRecipe(recipe->GetID())) {
  11216. delete recipe;
  11217. return;
  11218. }
  11219. auto res = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  11220. if (res != devices.end())
  11221. index = res - devices.begin();
  11222. else
  11223. devices.push_back(recipe->GetDevice());
  11224. prl->AddRecipe(recipe);
  11225. database.SavePlayerRecipe(GetPlayer(), recipe->GetID());
  11226. Message(CHANNEL_NARRATIVE, "Recipe: \"%s\" put in recipe book.", recipe->GetName());
  11227. if (packet && GetRecipeListSent()) {
  11228. packet->setArrayDataByName("id", recipe->GetID(), *i);
  11229. packet->setArrayDataByName("tier", recipe->GetTier(), *i);
  11230. packet->setArrayDataByName("level", recipe->GetLevel(), *i);
  11231. packet->setArrayDataByName("icon", recipe->GetIcon(), *i);
  11232. packet->setArrayDataByName("classes", recipe->GetClasses(), *i);
  11233. //packet->setArrayDataByName("skill", recipe->GetSkill(), *i);
  11234. packet->setArrayDataByName("technique", recipe->GetTechnique(), *i);
  11235. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), *i);
  11236. auto recipe_device = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  11237. if (recipe_device != devices.end())
  11238. packet->setArrayDataByName("device_type", recipe_device - devices.begin(), *i);
  11239. else
  11240. {//TODO error should never get here
  11241. }
  11242. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), *i);
  11243. packet->setArrayDataByName("recipe_name", recipe->GetName(), *i);
  11244. packet->setArrayDataByName("recipe_book", recipe->GetBook(), *i);
  11245. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), *i);
  11246. if(i) {
  11247. (*i)++;
  11248. }
  11249. }
  11250. }
  11251. bool Client::SetPlayerPOVGhost(Spawn* spawn) {
  11252. if(!spawn) {
  11253. pov_ghost_spawn_id = 0;
  11254. SendCharPOVGhost();
  11255. return true;
  11256. }
  11257. int32 ghost_id = player->GetIDWithPlayerSpawn(spawn);
  11258. if(ghost_id) {
  11259. pov_ghost_spawn_id = spawn->GetID();
  11260. SendCharPOVGhost();
  11261. return true;
  11262. }
  11263. return false;
  11264. }
  11265. void Client::HandleDialogSelectMsg(int32 conversation_id, int32 response_index) {
  11266. std::string conversation = "";
  11267. bool conv_established = false;
  11268. MConversation.lock_shared();
  11269. if (conversation_map.count(conversation_id) > 0 && conversation_map[conversation_id].count(response_index) > 0) {
  11270. conversation = std::string(conversation_map[conversation_id][response_index].c_str());
  11271. conv_established = true;
  11272. }
  11273. int32 spawn_id = conversation_spawns[conversation_id];
  11274. Item* item = conversation_items[conversation_id];
  11275. MConversation.unlock_shared();
  11276. if (GetCurrentZone()) {
  11277. Spawn* spawn = nullptr;
  11278. if(spawn_id) {
  11279. spawn = GetCurrentZone()->GetSpawnByID(spawn_id);
  11280. }
  11281. if (conv_established) {
  11282. if (spawn) {
  11283. if(conversation == "CloseItemConversation") {
  11284. LogWrite(LUA__ERROR, 0, "LUA", "CloseItemConversation is an invalid function call for this conversation with spawn id %u", spawn_id);
  11285. }
  11286. else {
  11287. GetCurrentZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_CONVERSATION, player, conversation.c_str());
  11288. }
  11289. }
  11290. else if (item && lua_interface && item->GetItemScript())
  11291. lua_interface->RunItemScript(item->GetItemScript(), conversation.c_str(), item, player);
  11292. else
  11293. CloseDialog(conversation_id);
  11294. }
  11295. else
  11296. CloseDialog(conversation_id);
  11297. }
  11298. }
  11299. bool Client::SetPetName(const char* petName) {
  11300. int8 result = database.CheckNameFilter(petName,4,31);
  11301. if (result == BADNAMELENGTH_REPLY) {
  11302. SimpleMessage(CHANNEL_COLOR_YELLOW, "Name length is invalid, must be greater then 3 characters and less then 31.");
  11303. return false;
  11304. }
  11305. else if (result == NAMEINVALID_REPLY) {
  11306. SimpleMessage(CHANNEL_COLOR_YELLOW, "Name is invalid, can only contain letters.");
  11307. return false;
  11308. }
  11309. else if (result == NAMETAKEN_REPLY) {
  11310. SimpleMessage(CHANNEL_COLOR_YELLOW, "Name is already taken, please choose another.");
  11311. return false;
  11312. }
  11313. else if (result == NAMEFILTER_REPLY) {
  11314. SimpleMessage(CHANNEL_COLOR_YELLOW, "Name failed the filter check.");
  11315. return false;
  11316. }
  11317. else if (result == UNKNOWNERROR_REPLY) {
  11318. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unknown error while checking the name.");
  11319. return false;
  11320. }
  11321. GetPlayer()->GetInfoStruct()->set_pet_name(petName);
  11322. return true;
  11323. }
  11324. bool Client::CheckConsumptionAllowed(int16 slot, bool send_message) {
  11325. switch(slot) {
  11326. case EQ2_FOOD_SLOT: {
  11327. if(GetPlayer()->GetSpellEffectBySpellType(SPELL_TYPE_FOOD)) {
  11328. if(send_message) {
  11329. Message(CHANNEL_NARRATIVE, "If you ate anymore you would explode!");
  11330. }
  11331. return false;
  11332. }
  11333. break;
  11334. }
  11335. case EQ2_DRINK_SLOT: {
  11336. if (GetPlayer()->GetSpellEffectBySpellType(SPELL_TYPE_DRINK))
  11337. {
  11338. if(send_message) {
  11339. Message(CHANNEL_NARRATIVE, "If you drank anymore you would explode!");
  11340. }
  11341. return false;
  11342. }
  11343. break;
  11344. }
  11345. default: {
  11346. if (GetVersion() <= 373) {
  11347. Item* item = GetPlayer()->item_list.GetItemFromIndex(slot);
  11348. if(item->IsFood()) {
  11349. if(item->IsFoodFood()) {
  11350. if(GetPlayer()->GetSpellEffectBySpellType(SPELL_TYPE_FOOD)) {
  11351. if(send_message) {
  11352. Message(CHANNEL_NARRATIVE, "If you ate anymore you would explode!");
  11353. }
  11354. return false;
  11355. }
  11356. return true;
  11357. }
  11358. else if(item->IsFoodDrink()) {
  11359. if (GetPlayer()->GetSpellEffectBySpellType(SPELL_TYPE_DRINK))
  11360. {
  11361. if(send_message) {
  11362. Message(CHANNEL_NARRATIVE, "If you drank anymore you would explode!");
  11363. }
  11364. return false;
  11365. }
  11366. return true;
  11367. }
  11368. }
  11369. }
  11370. return false;
  11371. break;
  11372. }
  11373. }
  11374. return true;
  11375. }
  11376. void Client::StartLinkdeadTimer() {
  11377. if(!linkdead_timer) {
  11378. int32 LD_Timer = rule_manager.GetGlobalRule(R_World, LinkDeadTimer)->GetInt32();
  11379. LogWrite(CCLIENT__DEBUG, 0, "Client", "Starting linkdead timer for %s (timer %u seconds)", GetPlayer()->GetName(), (LD_Timer/1000));
  11380. linkdead_timer = new Timer(LD_Timer);
  11381. linkdead_timer->Enable();
  11382. if(GetPlayer()->GetGroupMemberInfo()) {
  11383. LogWrite(CCLIENT__DEBUG, 0, "Client", "Telling player %s group they are disconnecting", GetPlayer()->GetName());
  11384. world.GetGroupManager()->GroupMessage(GetPlayer()->GetGroupMemberInfo()->group_id, "%s has gone Linkdead.", GetPlayer()->GetName());
  11385. }
  11386. }
  11387. }
  11388. bool Client::IsLinkdeadTimerEnabled() {
  11389. if(linkdead_timer) {
  11390. return linkdead_timer->Enabled();
  11391. }
  11392. return false;
  11393. }
  11394. void Client::SendNewAdventureSpells() {
  11395. SendNewSpells(player->GetAdventureClass());
  11396. int8 base_class = classes.GetBaseClass(player->GetAdventureClass());
  11397. int secondary_class = classes.GetSecondaryBaseClass(player->GetAdventureClass());
  11398. if(base_class != player->GetAdventureClass()) {
  11399. SendNewSpells(base_class);
  11400. }
  11401. if(secondary_class != player->GetAdventureClass() && secondary_class != base_class) {
  11402. SendNewSpells(secondary_class);
  11403. }
  11404. }
  11405. void Client::SendNewTradeskillSpells() {
  11406. SendNewTSSpells(player->GetTradeskillClass());
  11407. int8 secondary_class = classes.GetSecondaryTSBaseClass(player->GetTradeskillClass());
  11408. if(secondary_class != player->GetTradeskillClass()) {
  11409. SendNewTSSpells(secondary_class);
  11410. }
  11411. }
  11412. bool Client::AddRecipeBookToPlayer(int32 recipe_book_id, Item* item) {
  11413. Recipe* master_recipe = master_recipebook_list.GetRecipeBooks(recipe_book_id);
  11414. if(master_recipe) {
  11415. Recipe* recipe_book = new Recipe(master_recipe);
  11416. // if valid recipe book and the player doesn't have it
  11417. if (recipe_book && recipe_book->GetLevel() > GetPlayer()->GetTSLevel()) {
  11418. if(item) {
  11419. Message(CHANNEL_NARRATIVE, "Your tradeskill level is not high enough to scribe this book.");
  11420. }
  11421. safe_delete(recipe_book);
  11422. }
  11423. else if(recipe_book && item && !recipe_book->CanUseRecipeByClass(item, GetPlayer()->GetTradeskillClass())) {
  11424. if(item) {
  11425. Message(CHANNEL_NARRATIVE, "Your tradeskill class cannot use this recipe.");
  11426. }
  11427. safe_delete(recipe_book);
  11428. }
  11429. else if (recipe_book && (!item || !(GetPlayer()->GetRecipeBookList()->HasRecipeBook(recipe_book_id)))){
  11430. LogWrite(PLAYER__DEBUG, 0, "Recipe", "Valid recipe book that the player doesn't have");
  11431. // Add recipe book to the players list
  11432. if(!GetPlayer()->GetRecipeBookList()->HasRecipeBook(recipe_book_id)) {
  11433. GetPlayer()->GetRecipeBookList()->AddRecipeBook(recipe_book);
  11434. }
  11435. std::vector<Recipe*> recipes;
  11436. // Get a list of all recipes this book contains
  11437. if (item && item->recipebook_info) {
  11438. //Backup I guess if the recipe book is empty for whatever reason?
  11439. for (auto& itr : item->recipebook_info->recipes) {
  11440. Recipe* r = master_recipe_list.GetRecipeByCRC(itr); //GetRecipeByName(itr.c_str());
  11441. if (r) {
  11442. recipes.push_back(r);
  11443. }
  11444. }
  11445. LogWrite(PLAYER__DEBUG, 0, "Recipe", "%i recipes found for %s book", recipes.size(), recipe_book->GetBookName());
  11446. }
  11447. else {
  11448. LogWrite(PLAYER__ERROR, 0, "Recipe", "no recipes found for %s book", recipe_book->GetBookName());
  11449. }
  11450. //Filter out duplicate recipes the player already has
  11451. for (auto itr = recipes.begin(); itr != recipes.end();) {
  11452. Recipe* recipe = *itr;
  11453. if (GetPlayer()->GetRecipeList()->GetRecipe(recipe->GetID())) {
  11454. itr = recipes.erase(itr);
  11455. }
  11456. else itr++;
  11457. }
  11458. int16 i = 0;
  11459. // Create the packet to send to update the players recipe list
  11460. PacketStruct* packet = 0;
  11461. if (!recipes.empty() && GetRecipeListSent()) {
  11462. packet = configReader.getStruct("WS_RecipeList", GetVersion());
  11463. if (packet) {
  11464. packet->setArrayLengthByName("num_recipes", recipes.size());
  11465. }
  11466. }
  11467. for (int32 r = 0; r < recipes.size(); r++) {
  11468. Recipe* recipe = recipes[r];
  11469. if (recipe) {
  11470. Recipe* player_recipe = new Recipe(recipe);
  11471. AddRecipeToPlayerPack(player_recipe, packet, &i);
  11472. }
  11473. }
  11474. LogWrite(TRADESKILL__DEBUG, 0, "Recipe", "Done adding recipes");
  11475. database.SavePlayerRecipeBook(GetPlayer(), recipe_book->GetBookID());
  11476. if(item) {
  11477. database.DeleteItem(GetCharacterID(), item, 0);
  11478. GetPlayer()->item_list.RemoveItem(item, true);
  11479. }
  11480. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  11481. SetRecipeListSent(false);
  11482. SendRecipeList();
  11483. safe_delete(packet);
  11484. return true;
  11485. }
  11486. else {
  11487. if (recipe_book && item) {
  11488. Message(CHANNEL_NARRATIVE, "You have already learned all you can from this item.");
  11489. }
  11490. safe_delete(recipe_book);
  11491. }
  11492. }
  11493. else {
  11494. LogWrite(PLAYER__ERROR, 0, "Player", "%u recipe book id does not exist. Cannot AddRecipeToPlayer.", recipe_book_id);
  11495. }
  11496. return false;
  11497. }
  11498. bool Client::RemoveRecipeFromPlayer(int32 recipe_id) {
  11499. PlayerRecipeList* prl = GetPlayer()->GetRecipeList();
  11500. PacketStruct* packet = configReader.getStruct("WS_RecipeList", version);
  11501. Recipe* recipe = prl->GetRecipe(recipe_id);
  11502. int8 level = player->GetTSLevel();
  11503. if(packet && recipe) {
  11504. packet->setDataByName("command_type", 1);
  11505. packet->setArrayLengthByName("num_recipes", 1);
  11506. int32 myid = recipe->GetID();
  11507. int8 rlevel = recipe->GetLevel();
  11508. int8 even = level - level * .05 + .5;
  11509. int8 easymin = level - level * .25 + .5;
  11510. int8 veasymin = level - level * .35 + .5;
  11511. if (rlevel > level )
  11512. packet->setArrayDataByName("tier", 4, 0);
  11513. else if ((rlevel <= level) & (rlevel >= even))
  11514. packet->setArrayDataByName("tier", 3, 0);
  11515. else if ((rlevel <= even) & (rlevel >= easymin))
  11516. packet->setArrayDataByName("tier", 2, 0);
  11517. else if ((rlevel <= easymin) & (rlevel >= veasymin))
  11518. packet->setArrayDataByName("tier", 1, 0);
  11519. else if ((rlevel <= veasymin) & (rlevel >= 0))
  11520. packet->setArrayDataByName("tier", 0, 0);
  11521. if (rlevel == 2)
  11522. int xxx = 1;
  11523. packet->setArrayDataByName("recipe_id", myid, 0);
  11524. packet->setArrayDataByName("level", recipe->GetLevel(), 0);
  11525. packet->setArrayDataByName("unknown1", recipe->GetLevel(), 0);
  11526. packet->setArrayDataByName("icon", recipe->GetIcon(), 0);
  11527. packet->setArrayDataByName("classes", recipe->GetClasses(), 0);
  11528. packet->setArrayDataByName("technique", recipe->GetTechnique(), 0);
  11529. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), 0);
  11530. auto recipe_device = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  11531. if (recipe_device != devices.end())
  11532. packet->setArrayDataByName("device_type", recipe_device - devices.begin(), 0);
  11533. else
  11534. {//TODO error should never get here
  11535. }
  11536. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), 0);
  11537. packet->setArrayDataByName("recipe_name", recipe->GetName(), 0);
  11538. packet->setArrayDataByName("recipe_book", recipe->GetBook(), 0);
  11539. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), 0);
  11540. QueuePacket(packet->serialize());
  11541. }
  11542. safe_delete(packet);
  11543. bool res = prl->RemoveRecipe(recipe_id);
  11544. if(res) {
  11545. Query query;
  11546. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "DELETE FROM character_recipes where char_id=%u and recipe_id=%u", GetCharacterID(), recipe_id);
  11547. }
  11548. return res;
  11549. }
  11550. void Client::SaveSpells() {
  11551. MSaveSpellStateMutex.lock();
  11552. player->SaveSpellEffects();
  11553. player->SetSaveSpellEffects(true);
  11554. MSaveSpellStateMutex.unlock();
  11555. }
  11556. void Client::SendReplaceWidget(int32 widget_id, bool delete_widget, float x, float y, float z, int32 grid_id) {
  11557. Widget* new_spawn = new Widget();
  11558. new_spawn->SetWidgetID(widget_id);
  11559. new_spawn->SetLocation(grid_id);
  11560. new_spawn->SetWidgetX(x);
  11561. new_spawn->SetWidgetY(y);
  11562. new_spawn->SetWidgetZ(z);
  11563. new_spawn->SetX(x);
  11564. new_spawn->SetY(y);
  11565. new_spawn->SetZ(z);
  11566. EQ2Packet* ret = new_spawn->serialize(GetPlayer(), GetVersion());
  11567. QueuePacket(ret);
  11568. // we have to delete spawn* references anyway, we don't keep this widget live in the spawn list
  11569. GetPlayer()->RemoveSpawn(new_spawn, delete_widget);
  11570. safe_delete(new_spawn);
  11571. }
  11572. void Client::ProcessZoneIgnoreWidgets() {
  11573. GetPlayer()->MIgnoredWidgets.lock_shared();
  11574. std::map<int32, bool>::iterator itr;
  11575. for(itr = GetPlayer()->ignored_widgets.begin(); itr != GetPlayer()->ignored_widgets.end(); itr++) {
  11576. SendReplaceWidget(itr->first, true);
  11577. }
  11578. GetPlayer()->MIgnoredWidgets.unlock_shared();
  11579. }
  11580. void Client::PopulateRecipeData(Recipe* recipe, PacketStruct* packet, int i) {
  11581. if(!recipe || !packet)
  11582. return;
  11583. int8 level = player->GetTSLevel();
  11584. int32 myid = recipe->GetID();
  11585. int8 rlevel = recipe->GetLevel();
  11586. int8 even = level - level * .05 + .5;
  11587. int8 easymin = level - level * .25 + .5;
  11588. int8 veasymin = level - level * .35 + .5;
  11589. if (rlevel > level )
  11590. packet->setArrayDataByName("tier", 4, i);
  11591. else if ((rlevel <= level) & (rlevel >= even))
  11592. packet->setArrayDataByName("tier", 3, i);
  11593. else if ((rlevel <= even) & (rlevel >= easymin))
  11594. packet->setArrayDataByName("tier", 2, i);
  11595. else if ((rlevel <= easymin) & (rlevel >= veasymin))
  11596. packet->setArrayDataByName("tier", 1, i);
  11597. else if ((rlevel <= veasymin) & (rlevel >= 0))
  11598. packet->setArrayDataByName("tier", 0, i);
  11599. if (rlevel == 2)
  11600. int xxx = 1;
  11601. packet->setArrayDataByName("recipe_id", myid, i);
  11602. packet->setArrayDataByName("level", recipe->GetLevel(), i);
  11603. packet->setArrayDataByName("icon", recipe->GetIcon(), i);
  11604. packet->setArrayDataByName("classes", recipe->GetClasses(), i);
  11605. packet->setArrayDataByName("technique", recipe->GetTechnique(), i);
  11606. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), i);
  11607. packet->setArrayDataByName("device", recipe->GetDevice(), i);
  11608. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), i);
  11609. packet->setArrayDataByName("recipe_name", recipe->GetName(), i);
  11610. packet->setArrayDataByName("recipe_book", recipe->GetBook(), i);
  11611. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), i);
  11612. packet->setArrayDataByName("book_volume", 0x01, i);
  11613. packet->setArrayDataByName("device_id", 0x01, i);
  11614. }
  11615. int32 Client::GetRecipeCRC(Recipe* recipe) {
  11616. PacketStruct* packet = 0;
  11617. if (!(packet = configReader.getStruct("WS_RecipeDetailList", GetVersion()))) {
  11618. return 0;
  11619. }
  11620. packet->setArrayLengthByName("num_recipes", 1);
  11621. PopulateRecipeData(recipe, packet);
  11622. string* generic_string_data = packet->serializeString();
  11623. int32 size = generic_string_data->length();
  11624. if(size < 5)
  11625. return 0;
  11626. uchar* out_data = new uchar[size+1];
  11627. uchar* out_ptr = out_data;
  11628. memcpy(out_ptr, (uchar*)generic_string_data->c_str()+4, generic_string_data->length()-4);
  11629. uint32 out_crc = GenerateCRCRecipe(0, (void*)out_ptr, size-4);
  11630. safe_delete(packet);
  11631. safe_delete_array(out_data);
  11632. return out_crc;
  11633. }
  11634. void Client::SendRecipeDetails(vector<int32>* recipes) {
  11635. if(!recipes || recipes->size() == 0)
  11636. return;
  11637. PacketStruct* packet = 0;
  11638. if (!(packet = configReader.getStruct("WS_RecipeDetailList", GetVersion()))) {
  11639. return;
  11640. }
  11641. int32 recipe_size = player->GetRecipeList()->Size();
  11642. packet->setArrayLengthByName("num_recipes", recipe_size > 100 ? 100 : recipe_size);
  11643. int16 i = 0;
  11644. int32 count = 0;
  11645. vector<int32>::iterator recipe_itr;
  11646. for(recipe_itr = recipes->begin(); recipe_itr != recipes->end(); recipe_itr++) {
  11647. Recipe* recipe = player->GetRecipeList()->GetRecipe(*recipe_itr);
  11648. if(!recipe) {
  11649. continue;
  11650. }
  11651. else if(i > 99) {
  11652. QueuePacket(packet->serialize());
  11653. safe_delete(packet);
  11654. packet = configReader.getStruct("WS_RecipeDetailList", GetVersion());
  11655. recipe_size -= i;
  11656. packet->setArrayLengthByName("num_recipes", recipe_size > 100 ? 100 : recipe_size);
  11657. i = 0;
  11658. }
  11659. count++;
  11660. PopulateRecipeData(recipe, packet, i);
  11661. i++;
  11662. }
  11663. //packet->PrintPacket();
  11664. QueuePacket(packet->serialize());
  11665. safe_delete(packet);
  11666. }
  11667. ZoneServer* Client::GetHouseZoneServer(int32 spawn_id, int64 house_id) {
  11668. PlayerHouse* ph = nullptr;
  11669. HouseZone* hz = nullptr;
  11670. if(spawn_id) {
  11671. Spawn* houseWidget = GetPlayer()->GetSpawnByIndex(spawn_id);
  11672. if(houseWidget && houseWidget->IsWidget() && ((Widget*)houseWidget)->GetHouseID()) {
  11673. hz = world.GetHouseZone(((Widget*)houseWidget)->GetHouseID());
  11674. if (hz) {
  11675. ph = world.GetPlayerHouseByHouseID(GetPlayer()->GetCharacterID(), hz->id);
  11676. } else {
  11677. Message(CHANNEL_COLOR_YELLOW, "HouseWidget spawn index %u house zone could not be found.", spawn_id);
  11678. }
  11679. }
  11680. }
  11681. if(!ph && house_id) {
  11682. ph = world.GetPlayerHouseByUniqueID(house_id);
  11683. if (ph) {
  11684. hz = world.GetHouseZone(ph->house_id);
  11685. }
  11686. }
  11687. if (ph && hz) {
  11688. ZoneServer* house = zone_list.GetByInstanceID(ph->instance_id, hz->zone_id, false, true);
  11689. return house;
  11690. }
  11691. return nullptr;
  11692. }
  11693. void Client::SendHearCast(Spawn* caster, Spawn* target, int32 spell_visual, int16 cast_time) {
  11694. PacketStruct* packet = configReader.getStruct("WS_HearCastSpell", GetVersion());
  11695. if (packet) {
  11696. int32 caster_id = GetPlayer()->GetIDWithPlayerSpawn(caster);
  11697. int32 target_id = GetPlayer()->GetIDWithPlayerSpawn(target);
  11698. packet->setDataByName("spawn_id", caster_id);
  11699. packet->setArrayLengthByName("num_targets", 1);
  11700. packet->setArrayDataByName("target", target_id);
  11701. packet->setDataByName("num_targets", 1);
  11702. int32 visual = GetSpellVisualOverride(spell_visual);
  11703. packet->setDataByName("spell_visual", visual); //result
  11704. packet->setDataByName("cast_time", cast_time*.01f); //delay
  11705. packet->setDataByName("spell_id", 1);
  11706. packet->setDataByName("spell_level", 1);
  11707. packet->setDataByName("spell_tier", 1);
  11708. EQ2Packet* outapp = packet->serialize();
  11709. DumpPacket(outapp);
  11710. QueuePacket(outapp);
  11711. safe_delete(packet);
  11712. }
  11713. }
  11714. int32 Client::GetSpellVisualOverride(int32 spell_visual) {
  11715. int32 visual = spell_visual;
  11716. if(GetVersion() <= 561) { // spell's spell_visual field is based on newer clients, DoF has to convert
  11717. Emote* spellVisualEmote = visual_states.FindSpellVisualByID(visual, 60085);
  11718. if(spellVisualEmote != nullptr && spellVisualEmote->GetMessageString().size() > 0) {
  11719. spellVisualEmote = visual_states.FindSpellVisual(spellVisualEmote->GetMessageString(), GetVersion());
  11720. if(spellVisualEmote) {
  11721. visual = (int32)spellVisualEmote->GetVisualState();
  11722. }
  11723. }
  11724. }
  11725. return visual;
  11726. }